We help IT Professionals succeed at work.
Get Started

In GridView get cell value when check/uncheck CheckBox control for the same row.

Mohammad Alsolaiman
Last Modified: 2016-08-29
How could I get the value of a cell(Product ID) in Gridview , when clicking checkbox control on the same row of the gridview?
Please help.
my web form code here:
    <form id="form1" runat="server">
    <asp:GridView ID="GridView1" runat="server"  AllowPaging="True"  PageSize="4" AutoGenerateColumns="False" 
                        <asp:CheckBox ID="CheckBox1" runat="server" AutoPostBack="True"  />
                <asp:TemplateField HeaderText="Product ID">
                        <asp:Label ID="lblProductID" runat="server" Text='<%# Bind("ProductID") %>'></asp:Label>
                <asp:BoundField DataField="Name" HeaderText="Name" />
                <asp:BoundField DataField="Price" HeaderText="Price" />

Open in new window

my C# code here
public partial class EEquestion2 : System.Web.UI.Page
        salesDataContext db = new salesDataContext();
        protected void Page_Load(object sender, EventArgs e)
        private void BindData()
            var myProducts = db.Products;

            if ((myProducts != null) && (myProducts.Count() > 0))
                GridView1.DataSource = myProducts;

Open in new window

my gridview
Watch Question
Senior Engineer
This problem has been solved!
Unlock 2 Answers and 6 Comments.
See Answers
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE