Solved

How to read gridview column and checkbox value.

Posted on 2014-03-10
3
3,819 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

726 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