首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > asp.net >

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

2012-03-07 
GV里的Dropdownlist的postback事件写在哪里?前台页里的GV里的模版列里有一个dropdownlistasp:DropDownLis

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;
// ...
}

热点排行
Bad Request.