I am having a DropdownLIst in the HeaderTemplate of the Grid I have written some server side code on selectedINdexChanged event of this dropdown But this event never fires. I have also Enabled the ViewState of dropdown and the Page to true Ant ide what must be the Problem
Asked
Active
Viewed 1,058 times
1
-
1Have you set the autopostback of the dropdown to true? – ColinRobertson Oct 11 '11 at 09:43
-
2Show us the relevant code where you've created the DropDownList and where you bind it to its DataSource(or you've added the Items). – Tim Schmelter Oct 11 '11 at 09:43
2 Answers
1
I have solved this problem in my environment.... Please check out below code..
This is my gridview
in aspx page.
<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>
Get Grid View Bind in pageload event
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
GetTable();
grvGrid.DataSource = dstable;
grvGrid.DataBind();
}
}
Find DropDown control and bind it's event
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);
}
}
}
DropDown SelectedIndex Changes Event
protected void ddlMon_SelecdtedIndexChanges(object sender, EventArgs e)
{
// Your Code paste here
}

sikender
- 5,883
- 7
- 42
- 80
-
Do you get your answer of not!!!! you should accept your answer, if this things is right!!!! – sikender Oct 13 '11 at 04:50
0
Possible problem here is your DropDownList
might not set the property
AutoPostBack="true" try add this to your `DropDownList`

huMpty duMpty
- 14,346
- 14
- 60
- 99