gridview和下拉列表 [英] gridview and dropdownlist

查看:62
本文介绍了gridview和下拉列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我有一个gridview,这个gridview绑定到两个数据库表(使用Join).所有列都是模板字段.通常此gridview根据我的需要显示数据,但我也想使用编辑项目模板和页脚模板来编辑和添加记录.
因为在数据库中,它们是两个表之间的外主键关系.
因此,我已使用dropdownlist进行编辑并添加新记录(模板)以为一个表的外键列选择id.
我试图使用gridview的Row_DataBound()事件将它们绑定到dropdownlist,但是通过运行时异常,该对象未设置为引用.

因此,请向我建议其他方法,以将dropdownlist与gridview的edit和footer模板中的表中的数据绑定.

谢谢]

\\\\
Balwant

Hi,

I have a gridview and this gridview is bind to two database tables(Using Join). all column are template field.Normally this gridview show data as i want, but i also want to edit and add records using edit item template and footer template.
Because in the database their is foreign -primary key relation between two tables.
so i have used dropdownlist in for edit and add new records(template) to select id to foreign key column for one table.
I tried to bind these to dropdownlist using Row_DataBound() Event of gridview but it through exception at run time that object is not set to reference.

So please suggest me the other ways to bind dropdownlist with data from table in the edit and footer template of gridview.

thanks ]

\\\\
Balwant

推荐答案

做一件事添加dropdownlist事件

Do one thing add event of dropdownlist

<asp:dropdownlist id="ddl1" runat="server" onload="dropdown1_load">


在codebehind


in codebehind

protected void dropdown1_load(object sender,EventArgs e)
{
    SqlDataAdapter da = new SqlDataAdapter("select sno from student", cn);
    DataTable dt = new DataTable();
    da.Fill(dt);
    DropDownList ddl = (DropDownList)sender;
    ddl.DataSource = dt;
    ddl.DataTextField = "sno";
    ddl.DataValueField = "sno";
    ddl.DataBind();
}


这篇关于gridview和下拉列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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