Hello all,
with ref. to this post, http://www.aspsnippets.com/Articles/Bind-DropDownList-in-GridView-FooterTemplate-Footer-Row-in-ASPNet.aspx
I have placed a dropdown list in Gridview footer, now i want to access the dropdown selected indeex changed event as below. But i'm not able to access the event.
protected void ddlCatg_SelectedIndexChanged(object sender, EventArgs e)
{
DropDownList ddlCategories = grvExpenses.FooterRow.FindControl("ddlCatg") as DropDownList;
DropDownList ddlExpenseSubCategories = grvExpenses.FooterRow.FindControl("ddlSubCatg") as DropDownList;
ddlExpenseSubCategories.Items.Clear();
ddlExpenseSubCategories.Items.Insert(0, new ListItem("-Please Select-", "0"));
int Category = int.Parse(ddlCategories.SelectedValue);
PopulateExpenseSubCategories(Category);
}
protected void PopulateExpenseSubCategories(int Category)
{
DropDownList ddlExpenseSubCategories = grvExpenses.FooterRow.FindControl("ddlSubCatg") as DropDownList;
ddlExpenseSubCategories.DataSource = ExpensesBAL.GetExpenseSubCategories(Category);
ddlExpenseSubCategories.DataTextField = "sub_category";
ddlExpenseSubCategories.DataValueField = "sub_category";
ddlExpenseSubCategories.DataBind();
}
<asp:GridView ID="grvExpenses" runat="server" Width="100%"
AutoGenerateColumns="false" EmptyDataText="No Records found."
AlternatingRowStyle-BackColor="#C2D69B" HeaderStyle-BackColor="green"
ShowFooter="true" ondatabound="grvExpenses_DataBound">
<Columns>
<asp:TemplateField HeaderText="S.No">
<itemtemplate>
<asp:Label ID="lblSRNO" runat="server" Text='<%#Container.DataItemIndex+1 %>'></asp:Label>
<asp:Label runat="server" ID="lblId" Text='<%# Bind("s_no") %>' Visible="false"></asp:Label>
</itemtemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Category">
<ItemTemplate>
<%# Eval("expense_category")%>
</ItemTemplate>
<FooterTemplate>
<asp:DropDownList runat="server" ID="ddlCatg" AutoPostBack="true">
<asp:ListItem Text="Please Select" Value="0" Selected="True"></asp:ListItem>
</asp:DropDownList>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Sub Category">
<ItemTemplate>
<%# Eval("expense_sub_category")%>
</ItemTemplate>
<FooterTemplate>
<asp:DropDownList runat="server" ID="ddlSubCatg" AutoPostBack="true" OnSelectedIndexChanged="ddlCatg_SelectedIndexChanged">
<asp:ListItem Text="Please Select" Value="0" Selected="True"></asp:ListItem>
</asp:DropDownList>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Description">
<ItemTemplate>
<%# Eval("Remarks") %>
</ItemTemplate>
<FooterTemplate>
<asp:TextBox ID="txtRemarks" runat="server" />
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Cost">
<ItemTemplate>
<%# Eval("cost")%>
</ItemTemplate>
<FooterTemplate>
<asp:TextBox ID="txtcost" runat="server"></asp:TextBox>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Date">
<ItemTemplate>
<%# Eval("expense_date")%>
</ItemTemplate>
<FooterTemplate>
<asp:TextBox ID="txtDate" runat="server"></asp:TextBox>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField>
<ItemTemplate>
</ItemTemplate>
<FooterTemplate>
<asp:Button ID="btnAdd" runat="server" Text="Add" OnClick="Add" CommandName = "Footer" />
</FooterTemplate>
</asp:TemplateField>
</Columns>
<AlternatingRowStyle BackColor="#C2D69B" />
<EmptyDataTemplate>
<tr style="background-color: Green;">
<th scope="col">
Category
</th>
<th scope="col">
Sub Category
</th>
<th scope="col">
Description
</th>
<th scope="col">
Cost
</th>
<th scope="col">
Date
</th>
<th scope="col">
</th>
</tr>
<tr>
<td>
<asp:DropDownList runat="server" ID="ddlCatg" AutoPostBack="true" OnSelectedIndexChanged="ddlCatg_SelectedIndexChanged">
<asp:ListItem Text="Please Select" Value="0" Selected="True"></asp:ListItem>
</asp:DropDownList>
</td>
<td>
<asp:DropDownList runat="server" ID="ddlSubCatg" AutoPostBack="true">
<asp:ListItem Text="Please Select" Value="0" Selected="True"></asp:ListItem>
</asp:DropDownList>
</td>
<td>
<asp:TextBox ID="txtRemarks" runat="server" />
</td>
<td>
<asp:TextBox ID="txtcost" runat="server" />
</td>
<td>
<asp:Button ID="btnAdd" runat="server" Text="Add" OnClick="Add" CommandName = "EmptyDataTemplate" />
</td>
<td>
<asp:TextBox ID="txtDate" runat="server"></asp:TextBox>
</td>
</tr>
</EmptyDataTemplate>
</asp:GridView>