1
Answer

how to Check/Uncheck All checkboxs (Dynamically Generated) in Gridview

Muhammad Bilal Ahmad

Muhammad Bilal Ahmad

14y
4k
1

Hi to all,
I am new to ASP.NET, Can anyone help me ?
I am generating Dynamic Template fields (as per records in table) with one checkbox and one textbox in every row in GridView with a helper Class "GridViewTemplate".
And i am succeeded. But unable to understand how can i access these checkboxs when all these generated. Like to check/Uncheck All checkboxes in every row, when i check/uncheck the Header checkbox..
Please help me regarding this, if anyone can... I have uploaded the helper class.
and here is my codeBehind Code:
strSelect =
"select * from [Exam_Type] where Status_ID=1";
sqlSelect =
new SqlCommand(strSelect, con);
DataTable dt = new DataTable();
SqlDataAdapter dataAdapter = new SqlDataAdapter(sqlSelect);
dataAdapter.Fill(dt);
//foreach (DataRow col in dt.Rows)
for(;count<exam;count++)
{
DataColumn abc = new DataColumn();
//Declare the bound field and allocate memory for the bound field.
TemplateField bfield = new TemplateField();
bfield.HeaderTemplate = new GridViewTemplate(ListItemType.Header, test[count]);
bfield.ItemTemplate =
new GridViewTemplate(ListItemType.Item, test[count]);// abc.ColumnName);
//Add the newly created bound field to the GridView.
GridView1.Columns.Add(bfield);
//count++;
}
//Initialize the DataSource
GridView1.DataSource = dt;
 
AND
Page Code:
<
asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" BorderWidth="0px"
CssClass="grid_main" Width="250px" DataKeyNames="Exam_Type_ID" OnRowDataBound="GridView1_RowDataBound">
<Columns>
<asp:BoundField DataField="Title" HeaderText="Exam Type/Subjects" />
<asp:TemplateField Visible="False">
<ItemTemplate>
<asp:Label ID="lblSubjectID" runat="Server" ></asp:Label>
</ItemTemplate>
</asp:TemplateField>
</
Columns>
<HeaderStyle CssClass="grid_heading" />
</asp:GridView>
 
Any help will be really appreciated.
 
Thanks in advance.
Bilal Ahmad

Answers (1)