开发者

how to add checked event to checkbox in databound datagrid in asp.net?

开发者 https://www.devze.com 2023-03-19 11:34 出处:网络
I have datagridview with multiple columns in my asp.net website. And I am di开发者_运维问答splaying a backend sql stored procedure output into this grid using page OnLoad event. First column in the gr

I have datagridview with multiple columns in my asp.net website. And I am di开发者_运维问答splaying a backend sql stored procedure output into this grid using page OnLoad event. First column in the grid contains a checkbox. I have added this checkbox through ItemTemplate, so that all rows will have a checkbox for selecting the row. I want user able to select the checkbox and based on this selection I would like to perform a DB operation.

currently i am using like below, but couldn't able to trigger the event.

<asp:GridView ID="resultGridView" runat="server" >
            <Columns>
                <asp:TemplateField HeaderText="Processed">
                    <ItemTemplate>
                        <asp:CheckBox ID="CheckBoxProcess" runat="server" OnCheckedChanged="resultgrid_CellContentClick" 
                            Checked="false" />
                    </ItemTemplate>
                </asp:TemplateField>
            </Columns>
        </asp:GridView>

on my code behind, I have method resultgrid_CellContentClick() for checkbox selection change event. But this code, never executed when select checkbox on/off.


You didn't set AutoPostBack="true" in your checkbox, that's why your checkbox event handler did not work. Just set it...

 <asp:CheckBox ID="CheckBoxProcess" AutoPostBack="true" runat="server" 
 OnCheckedChanged="resultgrid_CellContentClick" Checked="false" />
0

精彩评论

暂无评论...
验证码 换一张
取 消