Click here to Skip to main content
15,885,546 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi i have a gridview i want to add text from textbox into gridview
text box how can i do so i have written the follw code on button click
 protected void Button1_Click(object sender, EventArgs e)
    {
       
        TextBox t1 = (TextBox)GridView1.FindControl("tt1");
        TextBox t2 = (TextBox)GridView1.FindControl("tt2");
        t.Text = TextBox1.Text;
        t1.Text = TextBox1.Text;

        t2.Text = TextBox1.Text;
} 


it is showing error as object not set to an instance of object
Posted
Updated 31-Jul-10 7:57am
v2
Comments
raju melveetilpurayil 31-Jul-10 14:04pm    
In which row you want to add text?
koool.kabeer 2-Aug-10 3:52am    
may be you have given the wrong Id of Control to search in GridView1....

1 solution

protected void Button1_Click(object sender, EventArgs e)
    {
        for (int i = 0; i < GridView1.Rows.Count; i++)
        {
           TextBox t1 = (TextBox)GridView1.Rows[i].FindControl("tt1");
           TextBox t2 = (TextBox)GridView1.Rows[i].FindControl("tt2");
           if(t1 != null)
           t1.Text = TextBox1.Text;
           if (t2 != null)
           t2.Text = TextBox1.Text;
       }
   }
 
Share this answer
 
v2
Comments
koool.kabeer 2-Aug-10 3:53am    
i would like to vote but not working here for me.....

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