Click here to Skip to main content
14,693,821 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Dear All,
I have been trying to figure out bellow but I really dont know what I am missing. I am trying to place an event for GridView CheckBox CheckedChanged event in RowDataBound, but it it doesent work.
bellow is the code for RowDataBound of a GridView

protected void gv_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            CheckBox c = (CheckBox)e.Row.Cells[0].Controls[0];
            c.Enabled = true;
            c.ID = e.Row.Cells[2].Text;
            c.ToolTip = e.Row.Cells[1].Text;
            c.AutoPostBack = true;
            c.CheckedChanged += chk_CheckedChanged;
        }
    }
    protected void chk_CheckedChanged(object sender, EventArgs e)
    {
        CheckBox cc = sender as CheckBox;
        Response.Write(cc.Checked.ToString());
    }


when I do Check or UnCheck the GridView CheckBox nothing happens.
any idea where my code goes wrong.
Posted

set
<checkbox id="chk"  runat="server" autopostback="true" and=""  öncheckedchange="chk_CheckedChanged" />
   
v2
Comments
Toniyo Jackson 14-Dec-10 6:15am
   
Always put your code inside code block.
Abdul Rahman Hamidy 19-Dec-10 0:51am
   
exactly this solved the problem, I added CheckBox as TemplateField and solved my problem, thanks alot Jackon, I appreciate!!!
You need to set AutoPostBack="true"

CheckBox in gridview with autopostback true [^]
   

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