GridView中嵌套DropDownList出问题啦 <asp:ListItem >男</asp:ListItem><asp:ListItem >女</asp:ListItem> 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 从GridView 中找到DropDownList 如:(GridView1.Rows[0].Cells[0].FindControl("DropDownList1") as DropDownList).Text; 这个就是 找到第一行第一列(第一个单元格)里面的DropDownList 选中的值 <ItemTemplate> <asp:DropDownList ID="ddlSort" runat="server" Width="98%"> </asp:DropDownList> <asp:HiddenField ID="Hd_Sort" runat="server" Value='<%# Eval("BalSort")%>' /></ItemTemplate> protected void gv_RowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.RowIndex != -1) { if (e.Row.RowState == DataControlRowState.Edit || e.Row.RowState == (DataControlRowState.Alternate | DataControlRowState.Edit)) { ((DropDownList)e.Row.FindControl("ddlSort")).SelectedValue = ((HiddenField)e.Row.FindControl("Hd_Sort")).Value; } } } protected void gv_RowEditing(object sender, GridViewEditEventArgs e) { gv.EditIndex = e.NewEditIndex; string strSort = ((DropDownList)gv.Rows[e.NewEditIndex].FindControl("ddlSort")).SelectedValue.Trim(); gv.EditIndex = -1; BindData(); } <EditItemTemplate> <asp:DropDownList ID="DropDownList1" runat="server" SelectedValue='Bind("Sex")'><asp:ListItem Text="男"></asp:ListItem> <asp:ListItem Text="女"></asp:ListItem> </asp:DropDownList></EditItemTemplate> <asp:DropDownList ID="DropDownList1" runat="server"><asp:ListItem ></asp:ListItem> <asp:ListItem Text="男"></asp:ListItem> <asp:ListItem Text="女"></asp:ListItem>加一个空项,如果你的数据库允许空值,可以再设置回去 我来解释详细通俗点: DropDownList 加载进GridView里面,想要知道某一行的DropDownList的值,需要通过后台在GridView中定位找到这行的DropDownList控件,才能进行取值。因为DropDownList加载进GridView中时,GridView每一行都会出现DropDownList控件,程序在运行时不能判断你具体操作的是哪一行DropDownList。DropDownList ddl = (DropDownList)gv.Rows[x].FindControl(“DropDownList的ID”);你需要取得值 = ddl.SelectedValue.Trim(); 那个放在 gridview 里面的控件是不能在页面直接找到的 ,需要在gridview里面找到这个控件获取他的值才可以 gridview里的控件是需要通过gridivew的单元格来找的!~ 把性别写在 dropdownlist的 text和 value 属性里面 Gridview 可以做成以双击某行进行“编辑”状态吗? 像这种情况我需要怎么做? asp.net GridView导出Excel 求助!asp.net c# 我不想用asp.net的表格控件。 求一个留言的sql语句,帮帮忙 求个简单的密码正则 代码基本上没有问题,grid就是不能更新,删除,希望得到高手的帮助 asp.net的真正的客户端控制! 求另一个页面调用日历日期返回框架中某个文本框的例子。。 各位高手!在Web窗体页中数据更新,使用数据集和使用执行sql语句直接访问数据库,哪个更好? sql分页效率问题 如何判断a页面是由b页面打开的?
<asp:DropDownList ID="ddlSort" runat="server" Width="98%">
</asp:DropDownList>
<asp:HiddenField ID="Hd_Sort" runat="server" Value='<%# Eval("BalSort")%>' />
</ItemTemplate>
protected void gv_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowIndex != -1)
{ if (e.Row.RowState == DataControlRowState.Edit || e.Row.RowState == (DataControlRowState.Alternate | DataControlRowState.Edit))
{
((DropDownList)e.Row.FindControl("ddlSort")).SelectedValue = ((HiddenField)e.Row.FindControl("Hd_Sort")).Value;
}
}
} protected void gv_RowEditing(object sender, GridViewEditEventArgs e)
{
gv.EditIndex = e.NewEditIndex;
string strSort = ((DropDownList)gv.Rows[e.NewEditIndex].FindControl("ddlSort")).SelectedValue.Trim();
gv.EditIndex = -1;
BindData();
}
<asp:DropDownList ID="DropDownList1" runat="server" SelectedValue='Bind("Sex")'>
<asp:ListItem Text="男"></asp:ListItem>
<asp:ListItem Text="女"></asp:ListItem>
</asp:DropDownList>
</EditItemTemplate>
<asp:ListItem ></asp:ListItem>
<asp:ListItem Text="男"></asp:ListItem>
<asp:ListItem Text="女"></asp:ListItem>
加一个空项,如果你的数据库允许空值,可以再设置回去
DropDownList 加载进GridView里面,想要知道某一行的DropDownList的值,需要通过后台在GridView中定位找到这行的DropDownList控件,才能进行取值。因为DropDownList加载进GridView中时,GridView每一行都会出现DropDownList控件,程序在运行时不能判断你具体操作的是哪一行DropDownList。
DropDownList ddl = (DropDownList)gv.Rows[x].FindControl(“DropDownList的ID”);
你需要取得值 = ddl.SelectedValue.Trim();
那个放在 gridview 里面的控件是不能在页面直接找到的 ,需要在gridview里面找到这个控件获取他的值才可以