Gridview
how to get textbox values from gridview cell using templatefield?
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
rakesh chaudhari57 reputationPosted Aug 17, 2012, 12:53 AM EDT
without loop
TextBox txtYourTextbox = (TextBox)gridview.Rows[0].FindControl("txtYourTextbox ");
string strTextboxvalue= txtYourTextbox .Text;
using loop
for (int j = i; j < gridview.Rows.Count; j++)
{
TextBox txtYourTextBox= (TextBox)gridview.Rows[i].FindControl("txtYourTextBox");
string strTextboxValue=txtYourTextBox.Text;
}
If It Is Usefull For U then Please reply me On [email protected],[email protected]
Deepak VermaRank #672 · 3.6K reputationPosted Aug 17, 2012, 1:38 AM EDT
You didn't specify where do you want TextBox or any other control, and there are various events where you can find controls inside GridView. For eg.
Finding TextBox inside Page_Load using foreach
protected void Page_Load(object sender, EventArgs e)
{
foreach (GridViewRow row in GridView1.Rows)
{
TextBox txt = row.FindControl("TextBox1") as TextBox;
txt.Text = row.RowType.ToString();
}
}
Finding TextBox inside GridView_RowCommand event
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "Action")
{
GridViewRow row = (e.CommandSource as Button).NamingContainer as GridViewRow;
TextBox txt = row.FindControl("TextBox1") as TextBox;
}
}
Finding TextBox inside GridView_RowDataBound event
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
TextBox txt;
if (e.Row.RowType == DataControlRowType.DataRow)
txt = e.Row.FindControl("TextBox1") as TextBox;
}
Sukesh MarlaRank #461 · 5.4K reputationPosted Aug 17, 2012, 2:09 AM EDT
GrdiViewRow row=MyGridView.Rows[0];//Rows[1],Rows[2],....
Texbox t=row.FindControl("myTextbox") as TextBox;
if(t!=null)
{
//t.Text;
}
Check this is correct answer if ir helped.