Click here to Skip to main content
16,012,168 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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...
C#
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
Updated 23-Dec-12 6:30am
v2

C#
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;
                    }
                }
 
Share this answer
 
v2

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900