Click here to Skip to main content
15,893,161 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I'm also got same problem...
i'm not able to retrieve data from dynamically created textbox inside the gridview.
you got any solution...
please help me.. if any other possibility having means...
Posted
Comments
/\jmot 25-Oct-14 9:50am    
place your code here,which you used but not working...

1 solution

Try this..

this will help you, i worked with it..working fine..

C#
foreach (GridViewRow row in gvItems.Rows)
{
String Str=Convert.ToString(((TextBox)row.FindControl("TextboxID")).Text);
}


C#
If this one not helping you, then place your code here, which's not working..or be more specific about your problem.
 
Share this answer
 
Comments
arulb2w 25-Oct-14 10:12am    
Thanks for your Quick reply Aajmot Sk..

This code is not working it shows an error "Object reference not set to an instance of an object"

Here my code..
.aspx

<asp:GridView ID="gridEmployee" Width="100%" runat="server" AutoGenerateColumns="False" OnRowDataBound="gridEmployee_RowDataBound" >



.aspx.cs
GridView gvDetails = View3.FindControl("gridEmployee") as GridView;
gvDetails.Columns.Clear();

//Operand Col
BoundField b5 = new BoundField();
b5.HeaderText = " ";
b5.DataField = "rno";
b5.ItemStyle.Width = 50;
gvDetails.Columns.Add(b5);
BoundField b4 = new BoundField();
b4.HeaderText = "Employee Details";
b4.DataField = "LabelName";
gvDetails.Columns.Add(b4);

TemplateField tf2 = new TemplateField();
tf2.HeaderText = "Value";
tf2.ItemStyle.Width = 250;
gvDetails.Columns.Add(tf2);

BoundField b3 = new BoundField();
b3.HeaderText = "FieldName";
b3.DataField = "FieldName";
b3.Visible = false;
gvDetails.Columns.Add(b3);

BoundField b1 = new BoundField();
b1.HeaderText = "FieldType";
b1.DataField = "FieldType";
b1.Visible = false;
gvDetails.Columns.Add(b1);

BoundField b2 = new BoundField();
b2.HeaderText = "CellType";
b2.DataField = "CellType";
b2.Visible = false;
gvDetails.Columns.Add(b2);

gvDetails.DataSource = dstFormChild.Tables[0];//i got data from Database in this datatable
gvDetails.DataBind();
ViewState["View3"] = dstFormChild.Tables[0];

protected void gridEmployee_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
string FieldName=(e.Row.DataItem as DataRowView).Row["FieldName"].ToString();
string Fieldtype = (e.Row.DataItem as DataRowView).Row["FieldType"].ToString();
string Celltype = (e.Row.DataItem as DataRowView).Row["CellType"].ToString();
string FieldSize = (e.Row.DataItem as DataRowView).Row["FieldSize"].ToString();
if (Celltype == "C")
{
DropDownList drpEmp = new DropDownList();
drpEmp.ID = "drp" + FieldName;
drpEmp.Width = 250;
GrdinsideCombo(drpEmp, FieldName);
e.Row.Cells[2].Controls.Add(drpEmp);
}
else
{
TextBox txtbox = new TextBox();
txtbox.ID = "txt" + FieldName;
txtbox.MaxLength = Convert.ToInt32(FieldSize);
txtbox.CssClass = Fieldtype.ToLower();
txtbox.Width = 250;
if (Fieldtype.ToLower() == "date")
txtbox.CssClass = "date";
e.Row.Cells[2].Controls.Add(txtbox);
}
}
}
/\jmot 25-Oct-14 10:33am    
place this code to your question so everyone can see this.
arulb2w 27-Oct-14 0:55am    
It's not working .. i'm getting Null exception error
foreach (GridViewRow row in gridEmployee.Rows)
{
String Str=Convert.ToString(((TextBox)row.FindControl("TextboxID")).Text);
}
/\jmot 25-Oct-14 10:34am    
if i get the solution i'll definately post to my ans.

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