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.

4
  • On which line do you get the error? Commented May 8, 2013 at 17:18
  • Line 68: Response.Write(chk.ToString()+vDescr); Line 69: Line 70: Commented May 8, 2013 at 17:20
  • The error raises just when you reach one of these lines, on which of them it raises? 66 or 67 or .....? I think it should be raised on line 67 ? Commented May 8, 2013 at 17:23
  • yes i think it is because ... once we want to try to print the value or apply some if condition, it gives error Commented May 8, 2013 at 17:28

2 Answers 2

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?

Sign up to request clarification or add additional context in comments.

Comments

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.