Solved

How to read gridview column and checkbox value.

Posted on 2014-03-10
3
3,608 Views
Last Modified: 2014-04-14
I have a grid view with binded data on it.
It has checkbox,verify and tid field in which verify field contains either 0 or 1, if verify field has 0 value row color is red and if 1 row color is green.
TID is list of unique numbers.

When if i click on checkbox and mark as check, the row color changes to green.
Now on submit button i want to read the tid number for every row where check box is checked.How to read that column and check whether checkbox is checked
as i want to update verify field at backend on click of submit button


The aspx of gridview is :
  <asp:GridView ID="GridView1" runat="server"   OnRowDataBound="GridView1_RowDataBound"
                    EnableModelValidation="True" ForeColor="#333333" GridLines="None"
                    BorderColor="#FFFFCC">
                 <Columns>
                <asp:TemplateField HeaderText="Select">
                <ItemTemplate>  
             
               
               <asp:CheckBox ID="myCheckBox" runat="server" />
                </ItemTemplate>
                 
                 
                </asp:TemplateField>
            </Columns>
              </asp:GridView>

code behind is:

  protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            int ve = Convert.ToInt32(DataBinder.Eval(e.Row.DataItem, "Verify"));
            if (ve == 0)
            {
                e.Row.ForeColor = Color.Red;

            }
            else if (ve == 1)
            {
                e.Row.ForeColor = Color.Green;
             
            }
            else
            {
                e.Row.ForeColor = Color.Red;
            }

        }
    }
    protected void btnsubmit_Click(object sender, EventArgs e)
    {

        foreach (GridViewRow row in GridView1.Rows)
        {

           
            if (((CheckBox)row.FindControl("cbm1")).Checked)
            {
               
 ?????????????????????
            }

        }
    }
0
Comment
Question by:searchsanjaysharma
  • 2
3 Comments
 
LVL 18

Accepted Solution

by:
Jerry Miller earned 500 total points
ID: 39918382
This is how I access the checkbox values:

C# Version:
foreach (GridViewRow Item in gridview.Rows) {
      MyCheckBox = (CheckBox)Item.FindControl("cbName");
      if (MyCheckBox.Checked) {
           'do domething here
      }
             }

VB version:
For Each Item As GridViewRow In gridview.Rows
            MyCheckBox = CType(Item.FindControl("cbName"), CheckBox)
            If MyCheckBox.Checked Then
               
                    'do something here

                End If
            End If
        Next
0
 

Author Comment

by:searchsanjaysharma
ID: 39919502
How to refer to current row in Girdview that is the corresponding tid column of any row
0
 

Author Closing Comment

by:searchsanjaysharma
ID: 39999676
tx
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now