I have 5 check box on my page and a Grid view with Template Field, I am not using any bond field on page load I am binding the grid with all data of a table, I want to filter the data based on the check box check.
suppose: I have check box like A B C D. All check box are out side of Grid view. When user checked the check box A, then in Grid view, check box A related data should show, like wise for B C and D.
how do that?, Some one please give some example code and bit logic.
It would be great if I'll be able to filter the gridview without any postback.
Grid:
<asp:GridView ID="GridView1" runat="server"
AutoGenerateColumns="False" CellPadding="3">
<Columns>
<asp:TemplateField HeaderText="ID" SortExpression="ID">
<ItemTemplate>
<asp:Label ID="lblId" runat="server" Text='<%#Eval("Id") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Discription" SortExpression="Discription">
<ItemTemplate>
<asp:Label ID="lblDiscription" runat="server" Text='<%#Eval("Discription") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Address" SortExpression="Address">
<ItemTemplate>
<asp:Label ID="lblAddress" runat="server" Text='<%#Eval("Address") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
Binding the Grid:
TestPageDao page1Dao = new TestPageDao ();
if (!IsPostBack)
{
IList<TestDAO> TestDAO = page1Dao.GetAlldata();
GridView1.DataSource = TestDAO;
GridView1.DataBind();
}
I tried Filter gridview or http://forums.asp.net/p/1034014/2904713.aspx
Best Answer
If you want to avoid postback, uses jQuery like here: http://jquerybyexample.blogspot.com/2012/04/how-to-filter-gridview-records-using.html
An alternative is AJAX, but at the end of the story it is a postback-like approach.
Finally using postback you can do it in several ways by dynamically setting the GridView filter before the GridView loads. This can be achieved with the Page load event, the OnSelecting of the associated datasource (if any), or similar.
Here it is an extraction of the aspx:
Note the OnSelecting event and note that there isn't any filter preset.
Now in the code behind set dynamically the filter:
If you don't like the OnSelecting event, you can do the same in the PageLoad:
I didn't test it so verify minor errors.