Click here to Skip to main content
15,897,519 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
private void updatetono()
   {
         DataTable dtpack = (DataTable)Session["gridviewupdate"];
           DataTable dtudate = new DataTable();
           for (int i = 0; dtpack.Rows.Count > i; i++)
        {
            CheckBox checks = (CheckBox)grdno.Rows[i].Cells[0].FindControl("gridviewtrans");
            if(checks.Checked)
            {
                dtudate = lo.updatehomeunactive(dtpack.Rows[i]["PkgName"].ToString());
                                             
            }
            else
            {

            }
        }

    

}


    protected void Updateno_Click(object sender, EventArgs e)
    {
        updatetono();
    }


<asp:GridView ID="grdno" runat="server" CellSpacing="2" Width="30%" CellPadding="4"
                    AutoGenerateColumns="False" ForeColor="#333333" Height="86px" alignment="left"
                    Style="margin-top: 3px">
                    <columns>
                            <asp:TemplateField HeaderText="Select">
                                <itemtemplate>
                                    <asp:CheckBox ID="gridviewtrans" runat="server"/>
                                </itemtemplate>
                            
                            <asp:TemplateField HeaderText="S.No." HeaderStyle-HorizontalAlign="Left">
                                <itemtemplate>
                                    <%# Container.DataItemIndex+1 %>
                                </itemtemplate>
                                <HeaderStyle HorizontalAlign="Left"></HeaderStyle>
                            
                            <asp:BoundField DataField="PkgName" HeaderText="PkgName" />
                            <asp:BoundField DataField="HomeActive" HeaderText="Status" />
                        </columns>
                      
                      <br />
                     <asp:Button ID="Updateno" runat="server"
                    Text="Update To No" onclick="Updateno_Click" />
                <br />


Aspx page code

ASP.NET
<asp:GridView ID="grdno" runat="server" CellSpacing="2" Width="30%" CellPadding="4"
                    AutoGenerateColumns="False" ForeColor="#333333" Height="86px" alignment="left"
                    Style="margin-top: 3px">
                    <Columns>
                            <asp:TemplateField HeaderText="Select">
                                <ItemTemplate>
                                    <asp:CheckBox ID="gridviewtrans" runat="server"/>
                                </ItemTemplate>
                            </asp:TemplateField>
                            <asp:TemplateField HeaderText="S.No." HeaderStyle-HorizontalAlign="Left">
                                <ItemTemplate>
                                    <%# Container.DataItemIndex+1 %>
                                </ItemTemplate>
                                <HeaderStyle HorizontalAlign="Left"></HeaderStyle>
                            </asp:TemplateField>
                            <asp:BoundField DataField="PkgName" HeaderText="PkgName" />
                            <asp:BoundField DataField="HomeActive" HeaderText="Status" />
                        </Columns>
                      </asp:GridView>
                      <br />
                 &nbsp;&nbsp;&nbsp;&nbsp;<asp:Button ID="Updateno" runat="server"
                    Text="Update To No" onclick="Updateno_Click" />
                <br />
Posted
Updated 14-Dec-15 0:14am
v2

1 solution

Hello ,
Modify your code and try this way
private void updatetono()
   {
         DataTable dtpack = (DataTable)Session["gridviewupdate"];
           DataTable dtudate = new DataTable();
           for (int i = 0; dtpack.Rows.Count > i; i++)
        {
           //change here
           CheckBox checks = (CheckBox)grdno.Rows[i].FindControl("gridviewtrans"); 
            if(checks != null && checks.Checked)
            {
                dtudate = lo.updatehomeunactive(dtpack.Rows[i]["PkgName"].ToString());                                             
            }
            else
            {
 
            }
        }  
 }

Thanks
 
Share this answer
 
v2
Comments
Member 12175752 15-Dec-15 0:44am    
still i am unable to find control of checkbox in gridview. i have tried all the solutions, but find control of checkbox in grid is coming false after i check the checkbox. please help me as soon as possible
Member 12175752 15-Dec-15 0:44am    
please review my above code and help me
Animesh Datta 15-Dec-15 1:06am    
I check the code and it runs fine , check whether 'dtpack' contains any data or not .
Member 12175752 15-Dec-15 1:12am    
yes sir, it contains data, data is coming fine in dtpack but it is not finding controls of checkbox in gridview. when i checks checkbox it showing false hen also.
Animesh Datta 15-Dec-15 1:20am    
Have u implement below line of code to get the CheckBox Control inside gridview
CheckBox checks = (CheckBox)grdno.Rows[i].FindControl("gridviewtrans");

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