protected virtual void DataGrid1_ItemDataBound(object sender, DataGridItemEventArgs e)
{
this.list = (DropDownList)e.Item.FindControl("edit_list");
if (list != null)
{
list.SelectedIndexChanged += new EventHandler(List_SelectedIndexChanged);
}
}
已分配列表,但selectedIndex eventHandler将不起作用
如果我让它RepairsStateList.BackColor = Color.Black;
它正在工作
protected void List_SelectedIndexChanged(object source, System.EventArgs e)
{
Response.Write("<script>alert('vv') </script>");
}
答案 0 :(得分:1)
AutoPostBack
属性必须设置为true ...
比你的代码必须
protected void dropdownlist1_SelectedIndexChanged(object sender, EventArgs e) {
// get reference to the row
GridViewRow gvr = (GridViewRow)(((Control)sender).NamingContainer);
// Get the reference of this DropDownlist
DropDownList dropdownlist1 = (DropDownList) gvr.FindControl("dropdownlist1");
}
修改强>
用
替换此行this.list = (DropDownList)e.Item.FindControl("edit_list");
这个
DropDownList list = (DropDownList)e.Item.FindControl("edit_list");
if (list != null)
{
list.SelectedIndexChanged += new EventHandler(List_SelectedIndexChanged);
}