Click here to Skip to main content
15,896,359 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
In gridview run mode as follows


Batchdate (only one column in gridview)
27 May 2015
30 May 2015

My code as follows

C#
  protected void gvPkgcbndate_RowDataBound(Object sender, GridViewRowEventArgs e)
    {
         
       if (e.Row.Cells[1].Text == "dontselect")
            {
                if (e.Row.RowType == DataControlRowType.DataRow)
                {
                    if (!(string.IsNullOrEmpty(e.Row.Cells[1].Text)))
                    {
                       LinkButton lnk = new LinkButton();
                       lnk.ID = "lnk ";
                       lnk.Text = "click here";

                e.Row.Cells[1].Controls.Add(lnk);
                   }
               }
    }


protected void lnk_Click(object sender, EventArgs e)
  {
      try
      {
var exist = lbllist.Items.FindByValue(gvPkgcbndate.SelectedRow.Cells[1].Text);
         string[] smsg = gvPkgcbndate.SelectedRow.Cells[1].Text.Split('-');
         string txt1 = smsg[1].ToString().Trim();
         lbllist.Items.Add(txt1.Substring(0, txt1.Length - 2));
      }
      catch (Exception ex)
      {
          lblErr.Text = ex.Message.ToString();

      }
  }

  protected void gvPkgcbndate_DataBound(object sender, EventArgs e)
    {
       lnk_Click(sender, e);
    }



But when i run shows error as follows in the lnk _click
error as follows

object referebce not set to an instance of object.

in lnk click i mention the below one is correct
gvPkgcbndate.SelectedRow.Cells[1].Text
Posted
Updated 27-Jul-15 10:04am
v2

1 solution

Use the debugger.
Put a breakpoint at the top of both the gvPkgcbndate_RowDataBoundand lnk_Clickmethods, and look at exactly what you are dealing with.

Use the debugger to examine the various variables and parts of variables (hover the mouse over them, or use the Watch pane) and find out which one is null.
We can't do that for you - we can't run your code, and we don't have your data!

When you know which one is null, you can start to look for why - but until you do know, there is nothing anyone can do.
 
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