Click here to Skip to main content
15,893,588 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
ASP.NET
<pre lang="HTML">

<div>
                    <asp:GridView ID="gdvReceivedLetter" runat="server" AllowPaging="True" AutoGenerateColumns="False"
                        CellPadding="3" DataKeyNames="ID" GridLines="Horizontal" EmptyDataText="No Records Found"
                        PageSize="10" Width="95%" BackColor="White" BorderColor="#E7E7FF" BorderStyle="None"
                        Font-Names="Arial" Font-Size="10.5" BorderWidth="1px" OnSelectedIndexChanged="gdvReceivedLetter_SelectedIndexChanged"
                        OnPageIndexChanging="gdvReceivedLetter_PageIndexChanging">
                        
                        <FooterStyle BackColor="#B5C7DE" ForeColor="#4A3C8C" />
                        <RowStyle BackColor="#E7E7FF" ForeColor="#4A3C8C" />
                        <Columns>
                            <asp:BoundField DataField="ID" HeaderText="ID" Visible="False"></asp:BoundField>
                            <asp:TemplateField Visible="true">
                                <HeaderTemplate>
                                    <input type="CheckBox" id="chkSelect" runat="server"  />
                                </HeaderTemplate>
                                <ItemTemplate>
                                    <asp:CheckBox runat="server" ID="chkDelete"  />   
                                </ItemTemplate>
                                <HeaderStyle Width="9px" />
                                <ItemStyle Width="9px" />
                            </asp:TemplateField>

            <asp:BoundField DataField="FileName" HeaderText="File Name">
                                <HeaderStyle CssClass="GridItemHeaderLarge" />
                                <ItemStyle CssClass="GridItemLarge" />
                            </asp:BoundField>                            

                        </Columns>
                        <PagerStyle BackColor="#E7E7FF" ForeColor="#4A3C8C" HorizontalAlign="Right" />
                        <SelectedRowStyle BackColor="#738A9C" Font-Bold="True" ForeColor="#F7F7F7" />
                        <HeaderStyle BackColor="#4A3C8C" ForeColor="#F7F7F7" />
                        <AlternatingRowStyle BackColor="#F7F7F7" />
                    </asp:GridView>
                </div>
    <table width="100%">
                    <tr>
                        <td width="80%">
                        </td>
                        <td width="20%" style="padding-removed 18px">
                            <asp:Button runat="server" ID="btnDelete" Text="Delete" Font-Bold="true" OnClientClick="return Delete();"
                                Enabled="true" OnClick="btnDelete_Click" />
                        </td>
                    </tr>
                </table>



C#
<pre lang="c#"> foreach (GridViewRow chkrow in gdvReceivedLetter.Rows)
                {
                    CheckBox chk = (CheckBox)chkrow.FindControl("chkDelete");
                    if (chk != null && chk.Checked)
                    {
                        Page.ClientScript.RegisterStartupScript(this.GetType(), "", "alert('CHECKEDDDDD');", true);   //////here is the PROBLEM
////exen the check box is checked the cursor never comes here!!! WHY!!????
                    }
                }
Posted
Comments
[no name] 5-May-12 7:10am    
From the very small snippet, either you don't have any rows in your gridview or the checkbox is null or the checkbox is not checked. Stepping through your code using a debugger will tell you why.
abhaysing2@gmail.com 5-May-12 7:16am    
:-( i checked it when grid box contain 8 rows and i check all the check box.... then also it not alerting :-((
[no name] 5-May-12 7:20am    
And what happened when you stepped through the code using your debugger? Did it go through the foreach loop? Did it find the checkbox? Did it run the line where you are registering a script function that doesn't exist? What?
abhaysing2@gmail.com 5-May-12 7:30am    
yep it go through foreach, it find the check box... but whenever the TracePoint comes onto the if loop it always find none of the checkboxex CHECKED :-(( means it never comes under the if loop only comes upto the IF loop then goes to foreach for next row....

1 solution

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