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:-
Articles
- Articles(C#.NET) (3)
- ASP.NET (6)
- Asp.Net(Email) (1)
- Asp.net(Image) (2)
- Asp.Net(Web.Config) (2)
- C#.NET (5)
- C#.NET Threading (3)
- C#.NET(ASP.NET) (4)
- Comments in PHP (1)
- Encryption In PHP (1)
- iPhone (Articles) (1)
- JavaScript (1)
- Json with PHP (1)
- LINQ (1)
- PHP (2)
- PHP Constant (1)
- PHP Operators (1)
- PHP Print Command (1)
- PHP Tutorial (2)
- Strings In PHP (1)
- Variable Declaration In PHP (1)
- WPF (1)
- XAML (2)
About Me
Help Link
Followers
Posted by
Sreejith A.K
Thursday, October 8, 2009
comments (0)
Labels:
ASP.NET
Subscribe to:
Posts (Atom)