Wednesday, 21 October 2015

How to Find Gridview Control on Button Click in Asp.Net C#

10/21/2015 - By Pranav Singh 0

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.


<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.







About the Author

We are the group of people who are expertise in different Microsoft technology like Asp.Net,MVC,C#.Net,VB.Net,Windows Application,WPF,jQuery,Javascript,HTML. This blog is designed to share the knowledge.

Get Updates

Subscribe to our e-mail newsletter to receive updates.

Share This Post

0 comments:

Please let me know your view

Free Ebooks


About Us

We are the group of people who are expertise in different Microsoft technology like Asp.Net,MVC,C#.Net,VB.Net,Windows Application,WPF,jQuery,Javascript,HTML. This blog is designed to share the knowledge.

Contact Us

For writing article in this website please send request by your

GMAIL ID: dotnetpools@gmail.com

Bugs and Suggestions

As we all know that this website is for sharing knowledge and providing proper solution. So while reading the article is you find any bug or if you have any suggestion please mail us at contact@aspdotnet-pools.com.

Partners


Global Classified : Connectseekers.com
© 2014 aspdotnet-pools.com Designed by Bloggertheme9.
back to top