Solved

How to read gridview column and checkbox value.

Posted on 2014-03-10
3
3,728 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

Are your AD admin tools letting you down?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

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

Suggested Solutions

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

810 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