16,011,947 members
Sign in
Sign in
Email
Password
Forgot your password?
Sign in with
home
articles
Browse Topics
>
Latest Articles
Top Articles
Posting/Update Guidelines
Article Help Forum
Submit an article or tip
Import GitHub Project
Import your Blog
quick answers
Q&A
Ask a Question
View Unanswered Questions
View All Questions
View C# questions
View C++ questions
View Javascript questions
View Visual Basic questions
View .NET questions
discussions
forums
CodeProject.AI Server
All Message Boards...
Application Lifecycle
>
Running a Business
Sales / Marketing
Collaboration / Beta Testing
Work Issues
Design and Architecture
Artificial Intelligence
ASP.NET
JavaScript
Internet of Things
C / C++ / MFC
>
ATL / WTL / STL
Managed C++/CLI
C#
Free Tools
Objective-C and Swift
Database
Hardware & Devices
>
System Admin
Hosting and Servers
Java
Linux Programming
Python
.NET (Core and Framework)
Android
iOS
Mobile
WPF
Visual Basic
Web Development
Site Bugs / Suggestions
Spam and Abuse Watch
features
features
Competitions
News
The Insider Newsletter
The Daily Build Newsletter
Newsletter archive
Surveys
CodeProject Stuff
community
lounge
Who's Who
Most Valuable Professionals
The Lounge
The CodeProject Blog
Where I Am: Member Photos
The Insider News
The Weird & The Wonderful
help
?
What is 'CodeProject'?
General FAQ
Ask a Question
Bugs and Suggestions
Article Help Forum
About Us
Search within:
Articles
Quick Answers
Messages
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);
}
}
}