I am trying to apply a filter to a gridview through a dropdown menu in a header template. However, after the option is selected, the page reloads and nothing has happened. I don't know why nothing is happening. I've tried many things and no filter came through. Can someone help me?
[code] <asp:GridView ID="GridView1" runat="server"
AllowPaging="false"
AllowSorting="true"
AutoGenerateColumns="false"
BorderStyle="None"
CellPadding="3"
CssClass="inboundTbl"
EnableModelValidation="True"
PageSize="20"
OnRowDataBound="GridView1_RowDataBound"
OnPageIndexChanging = "OnPaging"
Width="100%"
>[/code]
[code]<asp:TemplateField HeaderText="Current Terminal ID" SortExpression="VUCTID">
<HeaderTemplate>
Terminal:
<asp:DropDownList ID="ddlTerminal" runat="server"
AppendDataBoundItems = "true"
AutoPostBack="true"
OnSelectedIndexChanged="TerminalChanged"
>
<asp:ListItem Text="ALL" Value="ALL"></asp:ListItem> </asp:DropDownList>
</HeaderTemplate>
<ItemTemplate>
<%# Eval("VUCTID") %>
</ItemTemplate>
</asp:TemplateField>[/code]
private void BindGridView()
{
string query = @"This space was intentionally left blank.";
using (iDB2Connection conn = new iDB2Connection(connect))
{
using (iDB2Command cmd = new iDB2Command(query, conn))
{
conn.Open();
iDB2DataAdapter da = new iDB2DataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds);
DataTable dt = ds.Tables[0];
GridView1.DataSource = ds;
//iDB2DataReader reader;
//reader = cmd.ExecuteReader();
//GridView1.DataSource = reader;
GridView1.DataBind();
GridView1.GridLines = GridLines.Horizontal;
DropDownList ddlTerminal = (DropDownList)GridView1.HeaderRow.FindControl("ddlTerminal");
this.BindTerminalList(ddlTerminal);
string[] keys = new string[1];
keys[0] = "VUUNIT";
GridView1.DataKeyNames = keys;
ViewState["tab"] = ds.Tables[0];
}
}
}
protected void TerminalChanged(object sender, EventArgs e)
{
DropDownList ddlTerminal = (DropDownList)sender;
ViewState["Filter"] = ddlTerminal.SelectedValue;
this.BindGridView();
}
protected void OnPaging(object sender, GridViewPageEventArgs e)
{
GridView1.PageIndex = e.NewPageIndex;
this.BindGridView();
}