c# ItemDataBound 新事件处理程序
本文关键字:程序 事件处理 ItemDataBound | 更新日期: 2023-09-27 18:24:27
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);
}
}
列表已分配,但选定的索引事件处理程序不起作用如果我做RepairsStateList.BackColor = Color.Black;
它正在工作
protected void List_SelectedIndexChanged(object source, System.EventArgs e)
{
Response.Write("<script>alert('vv') </script>");
}
此下拉列表的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);
}