Click here to Skip to main content
16,004,602 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi guys!

I am trying to sort the records in my grid view by clicking the Header of any of the columns in my grid view. I read many articles about it and try them according to the instructions. When I tried to put it in codes, there is an error message saying "Object Reference not set to an instance of an object."

Here is my code where the error is. The error part is the line with Asterisks:
private DataView Getdata()
{
connection();
amicassaCon.Open();
DataSet dsMilestone = new DataSet();
string strSelectCmd = "SELECT[milestone_code],[milestone_name],[order_no],[milestone_status] FROM milestone ";
SqlDataAdapter da = new SqlDataAdapter(strSelectCmd, amicassaCon);
da.Fill(dsMilestone, "milestone");
***DataView dvMilestone = dsMilestone.Tables["milsetone"].DefaultView;
dvMilestone.Sort = ViewState["SortExpr"].ToString();
return dvMilestone;

}
Posted

1 solution

I solve it now! XD

private DataView Getdata()
{
connection();
amicassaCon.Open();
DataSet dsMilestone = new DataSet();
string strSelectCmd = "SELECT[milestone_code],[milestone_name],[order_no],[milestone_status] FROM milestone ";
SqlDataAdapter da = new SqlDataAdapter(strSelectCmd, amicassaCon);
da.Fill(dsMilestone, "milestone");
DataView dvMilestone = dsMilestone.Tables["milestone"].DefaultView;
dvMilestone.Sort = ViewState["SortExpr"].ToString();
return dvMilestone;

}

God Bless EVERYONE!
 
Share this answer
 

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