Click here to Skip to main content
15,889,732 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi folks,
I am facing problem.I wanna bind data to DropDown.Here my SP is
C#
ALTER PROCEDURE dbo.SelectAreaRouteInfo
	/*
	(
	@parameter1 int = 5,
	@parameter2 datatype OUTPUT
	)
	*/
AS
select routeinfo.routeid, area.areaname + ' / ' + routeinfo.routename from 
routeinfo inner join area 
on routeinfo.areaid  = area.areaid
	RETURN


DataTable dtAreaRoute = objAreaData.SelectRouteArea(objAreaBusiness);
            if (dtAreaRoute.Rows.Count > 0)
            {
                cmbDefaultRoute.DataSource = dtAreaRoute;
                cmbDefaultRoute.DataTextField = "AreaName";
                cmbDefaultRoute.DataValueField = "RouteID";
                cmbDefaultRoute.DataBind();

            }
        }

DataTextField="AreaName";
DataValueField = "RouteID";.Data coming from two table.Its not allowing me..given error

 Need your help.Thanks in advance.
Posted
Updated 11-Oct-13 0:40am
v3
Comments
[no name] 11-Oct-13 5:47am    
Your question is not clear where is the code where you are facing problem?
where are u binding, which language you are using to bind the drop down list?
JoCodes 11-Oct-13 5:54am    
Are you looking for some code which binds data for you using your stored procedure?
indrajeet jadhav 11-Oct-13 6:16am    
yes..Means In my Stored proc ..Inner join is used.data coming from different table
So RouteID may be DataValue field and DataTextField is AreaName..Means it..so here i am nt getting solution
JoCodes 11-Oct-13 8:10am    
I have posted a solution for binding the dropdown list using SP. once you fetch the join data from both tables into a dataset pass the datavalue and datatextfield accoringly.
JoCodes 11-Oct-13 8:11am    
Also use more appropriate question subject heading..

Hey there,

The problem is in your Stored Procedure and this line:
C#
mbDefaultRoute.DataTextField = "AreaName";

Your Stored Procedure is not returning any column with name AreaName because in your Select statement you are concatenating areaname with routename :
SQL
area.areaname + ' / ' + routeinfo.routename
which probably returns value but without a column name. Change the Select statement to this:
SQL
select routeinfo.routeid AS RouteID, area.areaname + ' / ' + routeinfo.routename AS AreaName from 
routeinfo inner join area 
on routeinfo.areaid  = area.areaid


It should work for you.

Do let me know if it does.

Azee...
 
Share this answer
 
Comments
indrajeet jadhav 11-Oct-13 7:08am    
Your query giving same result..Means your SP is also right..Give me coding solution
mbDefaultRoute.DataTextField = "?";
cmbDefaultRoute.DataValueField = "?";

or with using datatable ..??
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900