You must Sign In to post a response.
Category: ASP.NET
#765607
Hi,
I'm not clear about your requirement, but as per my understanding you want to insert the checked records into database right. If your requirement is like above then refer below sample.
Ex:
Hope this will helpful to you...
--------------------------------------------------------------------------------
Give respect to your work, Instead of trying to impress your boss.
N@veen
Blog : http://naveens-dotnet.blogspot.in/
I'm not clear about your requirement, but as per my understanding you want to insert the checked records into database right. If your requirement is like above then refer below sample.
Ex:
Protected void btnSave_Click(object sender, EventArgs e)
{
foreach(GridViewRow row in gv.Rows)
{
CheckBox chk=row.FindControl("chkSelect") as CheckBox;
if(chk)
{
//insert data in to database.
}
}
}
Hope this will helpful to you...
--------------------------------------------------------------------------------
Give respect to your work, Instead of trying to impress your boss.
N@veen
Blog : http://naveens-dotnet.blogspot.in/
#765610
Use findcontrol method of gridview row or cell to check if gridview checkbox is checked, see below snippet
Loop on each row and check
see below snippet
OR use in onrowcommand event and get cheked checkbox value.
Thanks
Koolprasd2003
Editor, DotNetSpider MVM
Microsoft MVP 2014 [ASP.NET/IIS]
Loop on each row and check
see below snippet
foreach (GridViewRow row in GridView1.Rows)
{
CheckBox chk = row.Cells[0].Controls[0] as CheckBox;
if (chk != null && chk.Checked)
{
// ...
}
}
OR use in onrowcommand event and get cheked checkbox value.
GridViewRow row = (GridViewRow)(((Control)e.CommandSource).NamingContainer);
int requisitionId = Convert.ToInt32(e.CommandArgument);
CheckBox cbox = (CheckBox)row.Cells[3].Controls[0];
Thanks
Koolprasd2003
Editor, DotNetSpider MVM
Microsoft MVP 2014 [ASP.NET/IIS]
#766393
Hi
try this code for Gridview Operations
Client Side
Server Side
Name : Dotnet Developer-2015
Email Id : kumaraspcode2009@gmail.com
'Not by might nor by power, but by my Spirit,' says the LORD Almighty.
try this code for Gridview Operations
Client Side
<asp:GridView ID="GridView211" runat="server" AutoGenerateSelectButton="True">
<Columns>
<asp:TemplateField HeaderText="IsApproved">
<ItemTemplate>
<asp:CheckBox ID="chkApproved" runat="server" CommandName="Approve" AutoPostBack="false" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
Server Side
protected void Btnsubmits_Click(object sender, EventArgs e)
{
foreach (GridViewRow row in GridView1.Rows)
{
CheckBox chk = (CheckBox)row.FindControl("chkApproved");
if (chk != null && chk.Checked)
{
SqlCommand sqlcmd = new SqlCommand("Insert into Tblcity values('Chennai');", con);
sqlcmd.ExecuteNonQuery();
}
}
}
Name : Dotnet Developer-2015
Email Id : kumaraspcode2009@gmail.com
'Not by might nor by power, but by my Spirit,' says the LORD Almighty.
Return to Return to Discussion Forum