In this article I will show you how you can detect checkbox
checked which is present in gridview using c#.net in asp.net on button click
event.
Some of my previous articles are as follows: Nested
GridView Using c#.Net In Asp.Net, Read
XML File in Dataset And Bind To GridView In Asp.Net Using C#.Net, Bind
XML File Data to Gridview By Category and SubCategory in Asp.Net Using C#.Net,
Comment
System OR Form and Display In GridView Using C# In Asp.Net, Hide
Or Show Gridview Column By Column Index at RunTime In Asp.Net Using C#.Net,
Hide
Or Show Gridview Row By Column Name at RunTime In Asp.Net Using C#.Net, Display
Grand Total In Gridview Footer On RowDataBound In Asp.Net Using C#.Net.
So for this article first we will create a new asp.net application and add a gridview control in it.
So for this article first we will create a new asp.net application and add a gridview control in it.
<asp:GridView ID="gvApproveRejectAdds" runat="server"
CssClass="gridtable"
AllowPaging="True"
ShowHeaderWhenEmpty="True" EmptyDataText="No records found"
AutoGenerateColumns="False" PageSize="10" Width="100%"
onpageindexchanging="gvApproveRejectAdds_PageIndexChanging">
<Columns>
<asp:TemplateField HeaderText="SELECT">
<HeaderTemplate>
<input id="chkSelectAll" type="checkbox" />
</HeaderTemplate>
<ItemTemplate>
<asp:CheckBox ID="chkItem"
runat="server"
CssClass="chkItem"/>
</ItemTemplate>
<ItemStyle Width="50px"
/>
</asp:TemplateField>
<asp:TemplateField HeaderText="ADD
LINK">
<ItemTemplate>
<a href='detail.aspx?id=<%#Eval("PostId") %>' target="_blank">
<%#Eval("Title")%></a>
<asp:HiddenField ID="hfId" runat="server"
Value='<%#Eval("PostId") %>'/>
</ItemTemplate>
<ItemStyle Width="200px"
/>
</asp:TemplateField>
<asp:TemplateField HeaderText="DETAIL">
<ItemTemplate>
<asp:TextBox ID="TextBox1"
runat="server"
TextMode="MultiLine"
Width="100%"
Height="30px"
Text='<%#Eval("RequestDetail") %>'></asp:TextBox>
</ItemTemplate>
<ItemStyle Width="200px"
/>
</asp:TemplateField>
</Columns>
<PagerSettings Position="TopAndBottom" />
</asp:GridView>
|
Now add the below code on button click event.
protected void
bthApproveall_Click(object sender, EventArgs e)
{
string
postId = "";
foreach
(GridViewRow row in
gvApproveRejectAdds.Rows)
{
CheckBox
chkPostItem = (CheckBox)row.FindControl("chkItem");
HiddenField
txtPostId = (HiddenField)row.FindControl("hfId");
}
}
|
Now run the application to check the output. Here is the
output what you get when you execute the code.
0 comments:
Please let me know your view