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 7:27am
GDdixit531
Edited 23-Dec-12 7:30am
CPallini337.4K
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 545
1 Maciej Los 475
2 Sascha Lefévre 289
3 CPallini 285
4 Sergey Alexandrovich Kryukov 274
0 Sergey Alexandrovich Kryukov 9,897
1 OriginalGriff 9,395
2 Peter Leow 5,162
3 Kornfeld Eliyahu Peter 3,373
4 Maciej Los 3,036


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