当前位置: 代码迷 >> ASP.NET >> GV里的Dropdownlist的postback事件写在哪里?该怎么解决
  详细解决方案

GV里的Dropdownlist的postback事件写在哪里?该怎么解决

热度:296   发布时间:2013-02-25 00:00:00.0
GV里的Dropdownlist的postback事件写在哪里?
前台页里的GV里的模版列里有一个dropdownlist
                      <asp:DropDownList   runat= "server "   ID= "WL "   AutoPostBack= "true ">
设置了自动回发.
但这是在一个GV里面.应该写在哪个事件中???

应该怎么得到dropdownlist的参数并进行操作???



------解决方案--------------------------------------------------------
直接使用页级事件处理程序

// .aspx
<asp:TemplateField>
<ItemTemplate>
<asp:DropDownList ID= "DropDownList1 " runat= "server " OnSelectedIndexChanged= "DropDownList1_SelectedIndexChanged ">
</asp:DropDownList>
</ItemTemplate>
</asp:TemplateField>


// .aspx.cs
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
DropDownList drp = sender as DropDownList; // 触发事件的 DDL
string val = drp.SelectedValue;
GridViewRow row = drp.NamingContainer as GridViewRow; // GridView 中对应的行
int id = (int)GridView1.DataKeys[row.RowIndex].Value;
// ...
}
  相关解决方案