我有一个转发器控件,在页脚中我有一个DropDownList.在我的代码隐藏中,我有:
protected void ddMyRepeater_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item
|| e.Item.ItemType == ListItemType.AlternatingItem)
{
// Item binding code
}
else if (e.Item.ItemType == ListItemType.Footer)
{
DropDownList ddl = e.Item.FindDropDownList("ddMyDropDownList");
// Fill the list control
ddl.SelectedIndexChanged += new
EventHandler(ddMyDropDownList_SelectedIndexChanged);
ddl.AutoPostBack = true;
}
}
Run Code Online (Sandbox Code Playgroud)
页面显示为PostBack但是我的EventHandler没有被调用.有任何想法吗?
Kyl*_*ser 11
如果你只想激活OnSelectedIndexChanged,它应该是这样的:
Page.aspx - 来源
<FooterTemplate>
<asp:DropDownList ID="ddlOptions"
runat="server"
AutoPostBack="true"
onselectedindexchanged="ddlOptions_SelectedIndexChanged">
<asp:ListItem>Option1</asp:ListItem>
<asp:ListItem>Option2</asp:ListItem>
</asp:DropDownList>
</FooterTemplate>
Run Code Online (Sandbox Code Playgroud)
Page.aspx.cs - 代码隐藏
protected void ddlOptions_SelectedIndexChanged(object sender, EventArgs e)
{
//Event Code here.
}
Run Code Online (Sandbox Code Playgroud)
就是这样.不需要更多.
如果DropDownList在Repeater中,然后激活SelectIndexChanged事件,则需要在GridView/Repeater上禁用EnableViewState.
例如
EnableViewState="false"
Run Code Online (Sandbox Code Playgroud)
您还需要在每个回发上对GridView/Repeater进行数据绑定,以便在Page Load方法中对其进行数据绑定.
归档时间: |
|
查看次数: |
14131 次 |
最近记录: |