GridView中的DropDownList控件,如何在进入编辑页面时,使DropDownList控件选定项为从数据库所读取记录值项? 如题,GridView控件绑定某表数据,表数据某列在编辑时,用DropDownList表示,现在GridView进入编辑状态,我需要DropDownList所选中的值是所对应记录的那个值。Please help me! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 可以用javascript来做,dropdownlist.value="选中列的值"即可 我就是不知道GridView中在编辑状态下,当前列的值如何取得并给DropDownList 你在DropDownList1那列的编辑模板列中加入一个HiddenField .给它绑定当前该条记录应该在DropDownList1上显示数据的Value值.用它来保存DropDownList1应该显示的值.在GridView1_RowDataBound事件中再它当前记录应该显示的值赋给DropDownList1.<EditItemTemplate><asp:DropDownList ID="DropDownList1" runat="server"><asp:HiddenField ID="HiddenField1" runat="server" Value='<%# Bind("字段") %>' /></EditItemTemplate> protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e) { if (((DropDownList)e.Row.FindControl("DropDownList1")) != null) { DropDownList1.SelectedValue = ((HiddenField)e.Row.FindControl("HiddenField1")).Value; } } DropDownList1显示的数据要不你在DropDownList1中写死了(包括它的text值与value值)要不你在后台给它绑定数据. DropDownList1.DataSource="数据源"; DropDownList1.DataTextField="字段"; DropDownList1.DataValueField="它段"; DropDownList1.DataBind(); 出去了一天多,回来又发现网络问题,今天试了加visible=false项,不行,不过没试过你上面的那种加在<EditItemTemplate /> 之间的,我会试一下,先谢了 Wow! It's work, thank you! 怎么检测 局域网的主机 是否开机 是否存在某个共享目录 紧急:MonthCalendar 怎么重写,修改它的天数背景色 长沙搞.net的公司 textbox定位问题 问个工作中遇到的问题,请教下.谢谢 哪位哥哥给小弟看看 数据库,添加 代码哪错了~ 小弟刚学的~请各位给看看~在线等 C# 隐藏其他进程托盘图标 winform中向数据库中写入图片 怎么让窗体半透明,而控件不透明 C#执行exe文件 多国语言的问题 求助大虾
应该在DropDownList1上显示数据的Value值.用它来保存DropDownList1应该显示的值.
在GridView1_RowDataBound事件中再它当前记录应该显示的值赋给DropDownList1.<EditItemTemplate>
<asp:DropDownList ID="DropDownList1" runat="server">
<asp:HiddenField ID="HiddenField1" runat="server" Value='<%# Bind("字段") %>' />
</EditItemTemplate>
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (((DropDownList)e.Row.FindControl("DropDownList1")) != null)
{
DropDownList1.SelectedValue = ((HiddenField)e.Row.FindControl("HiddenField1")).Value;
}
}
要不你在后台给它绑定数据. DropDownList1.DataSource="数据源";
DropDownList1.DataTextField="字段";
DropDownList1.DataValueField="它段";
DropDownList1.DataBind();