Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

How to read gridview column and checkbox value.

Posted on 2014-03-10
3
Medium Priority
?
4,044 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 1500 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

Tech or Treat! - Giveaway

Submit an article about your scariest tech experience—and the solution—and you’ll be automatically entered to win one of 4 fantastic tech gadgets.

Question has a verified solution.

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

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!
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Screencast - Getting to Know the Pipeline
Suggested Courses

597 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