0
  1. I am beginner and question or syntax may be silly.
  2. I have drawn a grid view having based on a SqlDataSource query.
  3. Converted a status field into Bit.
  4. a checkbox is automatically created.

now how can i get the value of checkbox on SelectedIndexChanged.

        protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
    {
        Panel_Entry.Visible = true;
        int i = GridView1.SelectedIndex;
        String vDescr = GridView1.Rows[i].Cells[2].Text;
        CheckBox chk = (CheckBox)GridView1.Rows[i].FindControl("BitStatus");
        Response.Write(chk.ToString()+vDescr);}

System.NullReferenceException: Object reference not set to an instance of an object.

error is shown. please help in this regard.

classic classic
  • 53
  • 1
  • 2
  • 7

2 Answers2

1

when you add a control dynamically , you should load the control again and it will not list in control tree.for finding it you can use a loop to find it like it is said in this post Better way to find control in ASP.NET

Also look at this post too: it seems useful ASP.Net FindControl is not working - How come?

Community
  • 1
  • 1
Maryam Arshi
  • 1,974
  • 1
  • 19
  • 33
0

thanks everybody...I have found the solution.

CheckBox chk = (CheckBox)GridView1.Rows[i].Cells[3].Controls[0]; if (chk.Checked) { Response.Write("yes"); } else { Response.Write("no"); } it is working fine. findcontrol() works if we are using some asp:template itemtemplate etc.

classic classic
  • 53
  • 1
  • 2
  • 7