Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: ASP.NET ASP:NET 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 6:27am
GDdixit523
Edited 23-Dec-12 6:30am
CPallini313.5K
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
0 OriginalGriff 310
1 Sergey Alexandrovich Kryukov 166
2 PhilLenoir 164
3 Richard MacCutchan 160
4 Sharmanuj 146
0 Sergey Alexandrovich Kryukov 6,081
1 OriginalGriff 5,115
2 CPallini 2,473
3 Richard MacCutchan 1,597
4 Abhinav S 1,505


Advertise | Privacy | Mobile
Web03 | 2.8.140814.1 | Last Updated 23 Dec 2012
Copyright © CodeProject, 1999-2014
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