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.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Sukesh MarlaPosted Aug 17, 2012, 6:09 AM
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.
Deepak VermaPosted Aug 17, 2012, 5:38 AM
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;
}
rakesh chaudhariPosted Aug 17, 2012, 4:53 AM
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]