Click here to Skip to main content
15,897,371 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
protected void CovidSelfDecleartionDeatils_RowCommand(object sender, GridViewCommandEventArgs e)
      {
          try
          {

              if (e.CommandArgument != "")
              {
                  int Index = Convert.ToInt32(e.CommandArgument);
               if (e.CommandName=="Select")
              {
                  GridViewRow clickedRow = CovidSelfDecleartionDeatils.Rows[Index];
                  Session["Filepath"] = clickedRow.Cells[9].Text;
                  //Session["Filepath"] = CovidSelfDecleartionDeatils.Rows[Index].FindControl("FilePath");
                  Session["Filepath1"] = CovidSelfDecleartionDeatils.DataKeys[Index]["Filepath"].ToString();
                  string filepath = Session["Filepath"].ToString();
              }
              }

          }
          catch
          {

          }
      }


What I have tried:

Whats is error in this code why showing excetion
Object reference not set to an instance of an object. in this column showing value
Posted
Updated 1-Apr-21 0:24am
Comments
Member 12700993 1-Apr-21 6:37am    
I am getting value in the index but my column is visible=false

1 solution

The message tells you that you are using a reference that has not been initialise to an object. So look at the line that the error occurs on to find out why.

Also do not use Convert.ToInt32 as it will fail if the string contains invalid characgters. Use Int32.TryParse Method (System) | Microsoft Docs[^] so you can catch errors.

And never write
C#
catch
{

}

that is just a waste of typing. The whole reason for using try/catch is to capture problems in your code and take action to either resolve them (if possible) or report them to the user.
 
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