Click here to Skip to main content
12,623,930 members (29,361 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: ASP.NET
hello bros....
i have a grid view..

on button click i want to enter some data of lines which r checked by check box..

for this i write the code...
string str;
    protected void Button2_Click(object sender, EventArgs e)
    {
        
 

        
        foreach (GridViewRow gvr in GridView1.Rows)
        {
              int rrowindx= gvr.RowIndex;
            CheckBox cbb = (CheckBox)GridView1.Rows[rrowindx].Cells[6].Controls[1];
            TextBox txt = (TextBox)GridView1.Rows[rrowindx].Cells[6].Controls[2];
 

==============================================================================
             str= GridView1.Rows[rrowindx].Cells[0].Text.ToString();
              //this 'str ' not returning any value.
==============================================================================
 
            if(cbb.Checked)
            {
            SqlConnection con = new SqlConnection("Data Source=GAURAV-PC\\SQLEXPRESS;Initial Catalog=mydatabase;Integrated Security=True");
            cmd = con.CreateCommand();
            cmd.CommandText = "execute this @Eid,@txtvalue";
            cmd.Parameters.Add("@Eid", SqlDbType.Int).Value = str;
            cmd.Parameters.Add("@txtvalue", SqlDbType.VarChar).Value = txt.Text;
 
            
 
        }}
    }

******** there is no value coming in str..this is ma problem
Posted 23-Dec-12 7:27am
GDdixit542
Updated 23-Dec-12 7:30am
CPallini393K
v2
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 2

foreach (GridViewRow gvr in GridView1.Rows)
                {
                    CheckBox cbb = (CheckBox)gvr.Cells[6].Controls[1];
                    if (cbb.Checked)
                    {
                        TextBox txt = (TextBox)gvr.Cells[6].Controls[2];
                        string str = ((System.Web.UI.DataBoundLiteralControl)(gvr.Cells[0].Controls[0])).Text;
                        SqlConnection con = new SqlConnection("Data Source=GAURAV-PC\\SQLEXPRESS;Initial Catalog=mydatabase;Integrated Security=True");
                        SqlCommand cmd = con.CreateCommand();
                        cmd.CommandText = "execute this @Eid,@txtvalue";
                        cmd.Parameters.Add("@Eid", SqlDbType.Int).Value = str;
                        cmd.Parameters.Add("@txtvalue", SqlDbType.VarChar).Value = txt.Text;
                    }
                }
  Permalink  
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.161128.1 | Last Updated 23 Dec 2012
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100