Software Programs and Projects

This Software Programs and Projects include programing tips and technology using different languages like VC++,ASP,JSP C#.Net,PHP,VB.Net,JavaScript,ASP.NET .Software Programs and Projects blog mainly support to software programmers and provide help through the mail.

Find Checkbox control in each row of the Gridview and Check box is checked or not and also select and deselect all checkbox in the Gridview .Implement Findcontrol method in the Gridview ..




/// Find check box control in the Gridview and Check box is checked or not


protected void btnList_Click(object sender, EventArgs e)
{
//Get number of rows in the GridView
int iCount = this.grdCourse.Rows.Count;
this.lstCourseId.Items.Clear();
for (int iIndex = 0; iIndex < iCount; iIndex++)
{
//Find Checkbox control in each row of the gridview..
CheckBox chkCourceId = ((CheckBox)this.grdCourse.Rows[iIndex].FindControl("chkId"));
//If checkbox is checked
if (chkCourceId.Checked)
{
//Get Course Id in each row of the gridview..
string strCourceId = this.grdCourse.Rows[iIndex].Cells[1].Text.ToString();
//Add CourseId Value into the Listbox Control
this.lstCourseId.Items.Add(strCourceId);
}

}

}

// Select and deselect all checkboxes in te Griview Control


protected void chkSelectAll_CheckedChanged(object sender, EventArgs e)
{
//Get number of rows in the GridView
int iCount = this.grdCourse.Rows.Count;

//If Select All check Box is checked

if (this.chkSelectAll.Checked)
{
for (int iIndex = 0; iIndex < iCount; iIndex++)
{
//Find Checkbox control in each row of the gridview..
CheckBox chkCourceId = ((CheckBox)this.grdCourse.Rows[iIndex].FindControl("chkId"));
// If checkbox is not checked
if (!chkCourceId.Checked)
{
chkCourceId.Checked = true;
}
}
}
else
{
for (int iIndex = 0; iIndex < iCount; iIndex++)
{
//Find Checkbox control in each row of the gridview..
CheckBox chkCourceId = ((CheckBox)this.grdCourse.Rows[iIndex].FindControl("chkId"));
// If checkbox is checked in the gridview
if (chkCourceId.Checked)
{
chkCourceId.Checked = false;
}
}
}


}


Please aply these code into the design (html) page...


<asp:GridView ID="grdCourse" runat="server">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:CheckBox ID="chkID" runat="server" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>

<asp:Button ID="btnList" runat="server" OnClick="btnList_Click" Text="List" />

<asp:CheckBox ID="chkSelectAll" runat="server" AutoPostBack="True"
OnCheckedChanged="chkSelectAll_CheckedChanged" Text="Select All" />





















tag:-
Find Checkbox control in each row of the Gridview and Check box is checked or not and also select and deselect all checkbox in the Gridview