Sir,
I am getting an Null Reference Exception in dataset even though the dataset is not null and count > 0 in ASP.NET.
Please do a solution for this issue.
Here the code :-
The error line is - ddlProduct.DataSource=ds;
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.
Vincent Maverick DuranoPosted May 2, 2015, 9:27 AM
Your FindControl method causes this error. You are attempting to access your DropDownList that is located inside a GridView in which your GridView is not bounded with data yet. You need to move your code for populating your DropDownList at RowDataBound event to avoid null reference error.
Here's a quick example:
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e) {
if (e.Row.RowType == DataControlRowType.DataRow) {
DropDownList ddl1 = (DropDownList)e.Row.FindControl("DropDownList1");
//populate your dropdownlist here
}
}
Bineesh ViswanathPosted Apr 10, 2015, 3:10 AM
Khargesh RajputPosted Apr 10, 2015, 1:27 AM
and check ds.tables[0].rows.count has value or not
remove ds!= null from if
only check count
and check ddlproduct control found or not
then check ds rows count
Akhil GargPosted Apr 10, 2015, 1:17 AM
But you can initialize before setting it DropDownList ddlproduct=new DropDOwnList(); ddlproduct= .....
Bineesh ViswanathPosted Apr 10, 2015, 12:44 AM
Akhil GargPosted Apr 9, 2015, 7:35 AM
saravanagopi sPosted Apr 9, 2015, 7:06 AM
Ravi KumarPosted Apr 9, 2015, 4:13 AM
check the fallowing one
ddlproduct.Datasource=ds.tables[0].defaultview;