Click here to Skip to main content
15,896,522 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i m sorting grid data ascending and descending order...
my code yesterday worked properly but now it gives an error i.e
Error:-
Object reference not set to an instance of an object


my code is:-


C#
protected void btnsort_Click(object sender, EventArgs e)
   {
       String expression = GrdATDataView.Columns[0].HeaderText;
       String Dire = "";
       SortDirection direction;


       switch (DropDownList1.SelectedValue.ToString().Trim())
       {
           case "asc":
               direction = SortDirection.Ascending;
               Dire = " Asc";
               break;
           case "des":
               direction = SortDirection.Descending;
               Dire = " Desc";
               break;
           default:
               direction = SortDirection.Ascending;
               break;
       }

  DT.DefaultView.Sort = "PRODUCT_GROUP_DESC " + Dire; //here this error.
  GrdATDataView.DataSource = DT;
  GrdATDataView.DataBind();
   }


plz help me...
thanks in advance...
Posted
Updated 25-Oct-12 20:07pm
v2

Some objects in your code could be null, most likely DropDownList1.SelectedValue.
The most important lesson for you should be: learn to use the debugger of Visual Studio!
When you know how to use it, you can resolve such easy problems in virtually no time at all. And you can better learn from code written by other developers.
 
Share this answer
 
I have a guess that expression is giving the object reference to null, if you are running your web app/project where did the error was pointed? on that way you'll what should be checked if its not giving any try to put a break point on those values you are fetching it will give you an information on what specific control is giving the error.
 
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