I want to display class and section value from database in gridview header named class and section and then filter the record based on selected dropdown value in header class and section
<asp:GridView ID="GridView1" runat="server" Class="table table-striped table-bordered table-hover" AutoGenerateColumns="false" AllowPaging="false">
<Columns>
<asp:BoundField DataField="AdmissionNo" HeaderText="Admission No" ItemStyle-Width="30" />
<asp:BoundField DataField="ReferenceNo" HeaderText="Reference No" ItemStyle-Width="100" />
<asp:BoundField DataField="AdmissionDate" HeaderText="Admission Date" ItemStyle-Width="100" />
<asp:BoundField DataField="AcademicName" HeaderText="Year" ItemStyle-Width="100" />
<asp:BoundField DataField="CourseName" HeaderText="Course" ItemStyle-Width="100" />
<asp:TemplateField>
<HeaderTemplate>
<asp:ListBox ID="lstClass" runat="server" SelectionMode="Multiple" AutoPostBack="true" class="form-control" >
</asp:ListBox>
</HeaderTemplate>
<ItemTemplate>
<%# Eval("ClassName") %>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<HeaderTemplate>
<asp:ListBox ID="lstSection" runat="server" SelectionMode="Multiple" AutoPostBack="true" class="form-control" onselectedindexchanged="lstSection_SelectedIndexChanged">
</asp:ListBox>
</HeaderTemplate>
<ItemTemplate>
<%# Eval("SectionName") %>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="RollNo" HeaderText="Roll No" ItemStyle-Width="100" />
<asp:BoundField DataField="SName" HeaderText="Student Name" ItemStyle-Width="100" />
<asp:BoundField DataField="DOB" HeaderText="Date of Birth" ItemStyle-Width="100" />
<asp:BoundField DataField="Gender" HeaderText="Gender" ItemStyle-Width="100" />
<asp:BoundField DataField="BloodGroup" HeaderText="Blood Group" ItemStyle-Width="100" />
<asp:BoundField DataField="Religion" HeaderText="Religion" ItemStyle-Width="100" />
<asp:BoundField DataField="SCNIC" HeaderText="SCNIC" ItemStyle-Width="100" />
<asp:BoundField DataField="SPhone" HeaderText="Phone" ItemStyle-Width="100" />
<asp:BoundField DataField="ParentID" HeaderText="Family Code" ItemStyle-Width="100" />
<asp:BoundField DataField="FCNIC" HeaderText="Father CNIC" ItemStyle-Width="100" />
<asp:BoundField DataField="FName" HeaderText="Father Name" ItemStyle-Width="100" />
<asp:BoundField DataField="FPhone" HeaderText="Father Phone" ItemStyle-Width="100" />
<asp:BoundField DataField="FJob" HeaderText="Job" ItemStyle-Width="100" />
<asp:BoundField DataField="MName" HeaderText="Mother Name" ItemStyle-Width="100" />
<asp:BoundField DataField="MCNIC" HeaderText="Mother CNIC" ItemStyle-Width="100" />
<asp:BoundField DataField="MPhone" HeaderText="Mother Phone" ItemStyle-Width="100" />
<asp:BoundField DataField="MJob" HeaderText="Mother Job" ItemStyle-Width="100" />
<asp:BoundField DataField="Address" HeaderText="Address" ItemStyle-Width="100" />
<asp:BoundField DataField="GuardianName" HeaderText="Guardian Name" ItemStyle-Width="100" />
<asp:BoundField DataField="GCNIC" HeaderText="G CNIC" ItemStyle-Width="100" />
<asp:BoundField DataField="GPhone" HeaderText="Guardian Phone" ItemStyle-Width="100" />
<asp:BoundField DataField="GAddress" HeaderText="G Address" ItemStyle-Width="100" />
<asp:BoundField DataField="Qualification" HeaderText="Qualification" ItemStyle-Width="100" />
<asp:BoundField DataField="Income" HeaderText="Income" ItemStyle-Width="100" />
<asp:BoundField DataField="Email" HeaderText="Email" ItemStyle-Width="100" />
</Columns>
</asp:GridView>
code behind
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
this.BindGrid();
}
}
protected void BindGrid()
{
con = new SqlDbConnect();
con.SqlQuery("select [AdmissionNo],[ReferenceNo],[AdmissionDate],[AcademicName],[CourseName],[ClassName],[SectionName],[RollNo],[SName],[DOB],[Gender],[BloodGroup],[Religion],[SCNIC],[SPhone],[ParentID],[FCNIC],[FName],[FPhone],[FJob],[MName],[MCNIC],[MPhone],[MJob],[Address],[GuardianName],[GCNIC],[GPhone],[GAddress],[Qualification],[Income],[Email] from tblStdReg as s inner join tblAcademicYear as a on s.YearID=a.YearID inner join tblCourse as c on s.CourseID=c.CourseID inner join tblDefClass as dc on s.ClassID=dc.ClassID inner join tblDefSection as ds on s.SectionID=ds.SectionID");
adapt.SelectCommand = con.Cmd;
adapt.Fill(sTable);
if (sTable.Rows.Count > 0)
{
GridView1.DataSource = sTable;
GridView1.DataBind();
lblTotal.Text = GridView1.Rows.Count.ToString();
}
else
{
Response.Write("No Record Found");
lblTotal.Text = "0";
return;
}
}