Click here to Skip to main content
15,890,557 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi i implemented a textbox in gridview

how can i update that textbox in gridview

plese help me
Posted
Comments
PK DotNet 18-Jun-10 3:38am    
Give me the small code that what u have down then i will help U.
Ankur\m/ 18-Jun-10 6:32am    
Your question doesn't make much sense. Do you mean you want to bind textbox to some value from database?

hi friend,

You can use this line in .cs form for access the textbox
Control text1 = (TextBox)GridView1.Row[0].Columns[0].FindControl[1];
string strtext = (TextBox)text1.Text;


Accept this answer if it is helpful to you.

Thanks,
Mahesh Patel
 
Share this answer
 
v2
you can use for loop to traverse the grid

TextBox txtBox = new TextBox();

for each (gridview row in gridview.rows)
  {
     txtBox = (TextBox)GridView1.Row[row.rowindex].Columns[0].FindControl[1];
     string strtext = (TextBox)txtBox.Text;
  }


regards
koolprasad2003
 
Share this answer
 
v2
Comments
Henry Minute 18-Jun-10 9:07am    
All your code will do is give the value from the last row. Putting someone else's answer into a loop (and failing) does not help the OP.
hi,

how to get TextBox control's value in gridview. I write some small codes. Hope help u.

In html Page:
<pre lang="xml"><asp:GridView runat=server ID=GridView1  CellPadding=3 CellSpacing=0 AutoGenerateColumns=false>
  <Columns>
   <asp:TemplateField HeaderText="Column1">
     <ItemTemplate>
     <asp:TextBox runat=server ID=TextBox1 Width=250px />
     </ItemTemplate>
   </asp:TemplateField>
  <asp:BoundField DataField="Column1" HeaderText="Column1" />
     <asp:BoundField DataField="Column2" HeaderText="Column2" />
     <asp:BoundField DataField="Column3" HeaderText="Column3" />
  </Columns>
  </asp:GridView>


In code page:
private void Update()
{
   foreach (GridViewRow GridViewRow1 in this.GridView1.Rows)
            {
                TextBox tb = (TextBox)GridViewRow1.FindControl("TextBox1");
                //if have control name 'TextBox1'
                if (tb != null)
                {
                    //get textbox control's value of each row in gridview
                   string value = tb.Text;
                }
            }
}
 
Share this answer
 

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