0

I use this code for gridview:

    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {   if (e.Row.RowType == DataControlRowType.DataRow)
        {
            e.Row.Attributes.Add("style", "font-weight:bold;color:blue");
            e.Row.Attributes.Add("style", "cursor:pointer;");
            e.Row.Attributes.Add("onclick", "location='WebForm1.aspx?id=" + DataBinder.Eval(e.Row.DataItem, "CustomerID") + "'";);
        }}

also use TemplateField to add a column of checkbox. my problem is when I click on any field of row goto WebForm1.aspx but I want when click on CheckBox no goto WebForm1.aspx page and only check CheckBox Control.

Coral Doe
  • 1,925
  • 3
  • 19
  • 36
SYSMAN
  • 3
  • 1
  • 8

2 Answers2

0

Take out the onclick event from your code.

 protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {   if (e.Row.RowType == DataControlRowType.DataRow)
        {
            e.Row.Attributes.Add("style", "font-weight:bold;color:blue");
            e.Row.Attributes.Add("style", "cursor:pointer;");

        }}
Paul Alan Taylor
  • 10,474
  • 1
  • 26
  • 42
0

I believe that you need to modify the last line to look for the checkbox control using the FindControl method and pass in the id of the checkbox control, something like this:

 e.Row.FindControl("myCheckBoxName").Attributes.Add("onclick", "location='WebForm1.aspx?id=" + DataBinder.Eval(e.Row.DataItem, "CustomerID") + "'";);
mreyeros
  • 4,359
  • 20
  • 24
  • can you elaborate as to what is not correct about the code? When you tested it did you receive an error or an exception? – mreyeros Dec 14 '11 at 18:52