Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 862689
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T09:11:00+00:00 2026-05-15T09:11:00+00:00

I am using checkboxs in a GridView. I need to determine the value in

  • 0

I am using checkboxs in a GridView. I need to determine the value in the cell in the 2nd column, if a checkbox has been checked.

I am using C# 2008 and ASP.net

                    <asp:GridView ID="gvOrders" runat="server" AutoGenerateColumns="False" CellPadding="4" GridLines="None" Width="100%" AllowPaging="True" PageSize="20" 
                    onpageindexchanging="gvOrders_PageIndexChanging" ForeColor="#333333">
                    <Columns>
                        <asp:TemplateField HeaderText="VerifiedComplete" >
                            <ItemTemplate>
                                <asp:CheckBox ID="cbPOID" runat="server"/>
                            </ItemTemplate>
                        </asp:TemplateField>
                        <asp:BoundField DataField="PurchaseOrderID" HeaderText="PurchaseOrderID" HtmlEncode="False" ></asp:BoundField>
                        <asp:BoundField DataField="VENDOR_ID" HeaderText="Vendor ID"></asp:BoundField>
                        <asp:BoundField DataField="VENDOR_NAME" HeaderText="Vendor Name"></asp:BoundField>
                        <asp:BoundField DataField="ITEM_DESC" HeaderText="Item Desc"></asp:BoundField>
                        <asp:BoundField DataField="SYS_DATE" HeaderText="System Date"></asp:BoundField>
                    </Columns>
                    <FooterStyle CssClass="GridFooter" BackColor="#990000" Font-Bold="True" ForeColor="White" />
                    <PagerStyle CssClass="GridPager" ForeColor="#333333" BackColor="#FFCC66" HorizontalAlign="Center" />
                    <SelectedRowStyle BackColor="#FFCC66" Font-Bold="True" ForeColor="Navy" />
                    <HeaderStyle CssClass="GridHeader" BackColor="#990000" Font-Bold="True" ForeColor="White"  />
                    <RowStyle CssClass="GridItem" BackColor="#FFFBD6" ForeColor="#333333" />
                    <AlternatingRowStyle  CssClass="GridAltItem" BackColor="White" />
                </asp:GridView>





        protected void btnDisable_Click(object sender, EventArgs e)
    {
            foreach (GridViewRow gvr in gvOrders.Rows)
            {

                if (((CheckBox)gvr.FindControl("cbPOID")).Checked == true)
                {
                    string strPrimaryid = gvr.Cells[2].ToString();
                }
            }

    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T09:11:01+00:00Added an answer on May 15, 2026 at 9:11 am

    Another way to do this, to avoid accessing the cells of the GridView by index, is to convert the desired BoundField to a TemplateField in the designer. Then use the FindControl method to get the text value in that cell. By default, the designer will give the Label control of the new TemplateField a name like “Label1.”

    I would add some pictures to show the designer part, if that process were easier. At any rate, the aspx would change like so, which you could do manually too:

    <asp:BoundField DataField="PurchaseOrderID" ...</asp:BoundField>
    

    becomes

    <asp:TemplateField HeaderText="PurchaseOrderID">
     <ItemTemplate>
      <asp:Label ID="Label1" runat="server" Text='<%# Bind("PurchaseOrderID") %>'></asp:Label>
     </ItemTemplate>
     <EditItemTemplate>
      <asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("PurchaseOrderID") %>'></asp:TextBox>
     </EditItemTemplate>
    </asp:TemplateField>
    

    Then you would make this simple code change:

    string strPrimaryid = gvr.FindControl("Label1").Text;
    

    However, I think a better way to do this is by utilizing the DataKeys features of the GridView control. The first step would be to set the DataKeyNames property of your GridView:

    <asp:GridView ID="gvOrders" runat="server" DataKeyNames="PurchaseOrderID" ...>
    

    Then, assuming your PurchaseOrderID column is of type int, you would change that same line to be:

    int primaryid = (int)gvOrders.DataKeys[gvr.RowIndex].Value;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a gridview that I have added a checkbox column using a templatefield
I am using Html.CheckBox() . The resulting HTML is: <input id=IsMultiGraph name=IsMultiGraph value=true type=checkbox>
Using preview 4 of ASP.NET MVC Code like: <%= Html.CheckBox( myCheckBox, Click Here, True,
I am using asp.net and I am trying to save checkbox values into a
can anybody show me how to build a string using checkbox. what would be
I'd like to do something like this to tick a checkbox using jQuery :
Is there a specific reason why I should be using the Html.CheckBox , Html.TextBox
I'm using a column of checkboxes in a YUI DataTable, I works fine. But
I'm using Zend_Form to output a set group of checkboxes: <label style=white-space: nowrap;><input type=checkbox
Using online interfaces to a version control system is a nice way to have

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.