Click here to Skip to main content
15,888,301 members

Comments by arulb2w (Top 2 by date)

arulb2w 27-Oct-14 0:55am View    
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);
}
arulb2w 25-Oct-14 10:12am View    
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);
}
}
}