我在网格的HeaderTemplate中有一个DropdownLIst 我在此下拉列表的selectedINdexChanged事件上写了一些服务器端代码 但是这个事件永远不会发生。 我还启用了ViewState的下拉菜单和Page为true Ant ide必须是什么问题
答案 0 :(得分:1)
我已经在我的环境中解决了这个问题....请查看以下代码..
gridview
。 <asp:GridView ID="grvGrid" runat="server" AllowPaging="True"
AllowSorting="True" AutoGenerateColumns="False" DataKeyNames="CustomerID" OnRowDataBound="grvGrid_RowDataBound">
<Columns>
<asp:BoundField DataField="CustomerID" HeaderText="CustomerID" ReadOnly="True"
SortExpression="CustomerID" />
<asp:BoundField DataField="CompanyName" HeaderText="CompanyName"
SortExpression="CompanyName" />
<asp:TemplateField>
<HeaderTemplate>
<%--<asp:Label ID="lblMon1" runat="server"></asp:Label>--%>
<asp:DropDownList id="ddlMon" runat="server" AutoPostBack="true" OnSelectedIndexChanged="ddlMon_SelecdtedIndexChanges">
<asp:ListItem Text="1" Value="1" Selected="True">1</asp:ListItem>
<asp:ListItem Text="2" Value="2">2</asp:ListItem>
<asp:ListItem Text="3" Value="3">3</asp:ListItem>
</asp:DropDownList>
</HeaderTemplate>
<ItemTemplate>
<asp:Label ID="lblblbl" runat="server"></asp:Label>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
GetTable();
grvGrid.DataSource = dstable;
grvGrid.DataBind();
}
}
protected void grvGrid_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (Page.IsPostBack)
{
if (e.Row.RowType == DataControlRowType.Header)
{
DropDownList ddlmon = e.Row.FindControl("ddlMon") as DropDownList;
ddlmon.SelectedIndexChanged += new EventHandler(ddlMon_SelecdtedIndexChanges);
}
}
}
protected void ddlMon_SelecdtedIndexChanges(object sender, EventArgs e)
{
// Your Code paste here
}
答案 1 :(得分:0)
此处可能出现的问题是DropDownList
可能未设置属性
AutoPostBack="true" try add this to your `DropDownList`