高手帮个忙?看看怎么给dataGrid里面的DropDownList赋值
<ItemTemplate>
<asp:DropDownList ID= "class_type " runat= "server ">
<asp:ListItem> 显示 </asp:ListItem>
<asp:ListItem> 不显示 </asp:ListItem>
</asp:DropDownList>
</ItemTemplate>
<EditItemTemplate>
<asp:DropDownList ID= "class_type " runat= "server " DataValueField= "class_type ">
<asp:ListItem Selected= " "> 显示 </asp:ListItem>
<asp:ListItem> 不显示 </asp:ListItem>
</asp:DropDownList>
</EditItemTemplate>
//数据绑定代码
protected void DataBindGrid()
{
SqlConnection myconn = new SqlConnection(SqlHelper.myconntionstring);
myconn.Open();
string sql = "Select * from DB_qiye_news_class order by id desc ";
SqlDataAdapter dr = new SqlDataAdapter(sql, myconn);
DataTable link_class = new DataTable();
dr.Fill(link_class);
myconn.Close();
DataGrid1.DataSource = link_class;
DataBind();//绑定完成
dr.Dispose();
}
问题:1 我该怎么样赋值给DropDownList
2 在DataGrid1_UpdateCommand里面我该怎么操作而获得DropDownList(里面的值为静态的)里面重新选择的值
[解决办法]
private void dlsList_ItemDataBound(object sender, System.Web.UI.WebControls.DataListItemEventArgs e)
{
DropDownList class_type = (DropDownList)(e.Item.FindControl( "class_type "));
}
[解决办法]
1.楼上已经回答了2.也是一样
[解决办法]
private void dlsList_ItemDataBound(object sender, System.Web.UI.WebControls.DataListItemEventArgs e)
{
DropDownList class_type = (DropDownList)(e.Item.FindControl( "class_type "));
class_type.SelectedValue = " ";
}
[解决办法]
一行行的赋值?foreach()这个不太确定 请教高手
取值
(DropDownList)(e.item.cells[X].controls[0])要转换成下拉列表
[解决办法]
1 在DataGrid的 DataGrid_ItemDataBound事件里面通过逐行获取DataListItemEventArgs e.
2 DropDownList dpl_search = (DropDownList)e.Item.FindControl( "你在aspx中定义的DropDownList的名称 ")
3 具体处理dpl_search
[解决办法]
DropDownList ddlist = ((DropDownList)DataGrid1.Items[e.Item.ItemIndex].Cells[0].Controls[0]);