Click here to Skip to main content
15,891,033 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I am doing a forum where i have textbox in gridview control in forum page.How to get the textbox value in a string so as to check the same value with the DB.I have tried like below but no use
C#
string Ques = (TextBox)GridViewFRM.Rows[i].Cells[0].FindControl("GVQuestionTextBox");
Posted
Updated 10-Oct-13 19:24pm
v2
Comments
Madhu Nair 14-Oct-13 2:08am    
In case you any of the solution has worked for you then please mark it as a solution as it would help others also.

Try this way -

C#
string Ques = ((TextBox)GridViewFRM.Rows[i].FindControl("GVQuestionTextBox")).Text; 
 
Share this answer
 
You are almost nearer. Try this.
C#
TextBox txt=(TextBox)GridViewFRM.Rows[i].Cells[0].FindControl("GVQuestionTextBox");
string Ques = txt.Text;//This will be desired one

Regards..
 
Share this answer
 
in button click event.. i tried like below and got the result what i was expecting

string FORID = GridViewFRM.Rows[e.RowIndex].Cells[index].Text;

index is the column number of the gridview

instead of treating it as textbox value, i treated & directly got it as a value from the gridview

thanks guys for all your response
 
Share this answer
 
v2
That will not work, you need an instance of the GridViewRow.
From an object oriented perspective, the Gridview has this hierarchy:

GridView fathers GridViewRow fathers Control

So, try:

C#
string Ques = ((TextBox)GridViewFRM.Rows[i].FindControl("GVQuestionTextBox")).Text;
 
Share this answer
 
thanks for response guys
will let you know after checking with your answers

thanks
 
Share this answer
 
C#
int i=e.NewEditrowindex;

TextBox Ques =(TextBox)GridViewFRM.Rows[i].Cells[0].FindControl("GVQuestionTextBox");
string Ques1 = Ques .Text;//This will be desired one
 
Share this answer
 
v2
TextBox txt=(TextBox)GridViewFRM.Rows[i].Cells[0].FindControl("GVQuestionTextBox").Text;
 
Share this answer
 
Comments
CHill60 26-Jun-14 7:54am    
Remarkably similar to other responses posted 8 months ago - with the addition of a bug ... did you really mean to assign Text (a string) to a TextBox

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