我想将数据绑定到DropDown [英] I want to bind data to DropDown

查看:114
本文介绍了我想将数据绑定到DropDown的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨伙计们,

我正面临问题。我想把数据绑定到DropDown。我的SP是

Hi folks,
I am facing problem.I wanna bind data to DropDown.Here my SP is

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.

推荐答案

嘿那里,



问题在于你的存储过程和这一行:

Hey there,

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



您的存储过程未返回名称为 AreaName 的任何列,因为在您的Select语句中您正在连接 areaname with routename


Your Stored Procedure is not returning any column with name AreaName because in your Select statement you are concatenating areaname with routename :

area.areaname + ' / ' + routeinfo.routename

可能返回值但没有列名。将Select语句更改为:

which probably returns value but without a column name. Change the Select statement to this:

select routeinfo.routeid AS RouteID, area.areaname + ' / ' + routeinfo.routename AS AreaName from 
routeinfo inner join area 
on routeinfo.areaid  = area.areaid





它应该适合你。



如果确实如此,请告诉我。



Azee ...



It should work for you.

Do let me know if it does.

Azee...


查看此链接



http://aspalliance.com/618_CodeSnip_Populate_a_DropDownList_with_a_Stored_Procedure [ ^ ]


这篇关于我想将数据绑定到DropDown的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆