Wrox Programmer Forums
ASP.NET 3.5 Professionals If you are an experienced ASP.NET programmer, this is the forum for your 3.5 questions. Please also see the Visual Web Developer 2008 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 3.5 Professionals section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old October 30th, 2009, 06:01 AM
Friend of Wrox
Join Date: Jan 2006
Posts: 180
Thanks: 1
Thanked 1 Time in 1 Post
Send a message via ICQ to dpkbahuguna Send a message via MSN to dpkbahuguna Send a message via Yahoo to dpkbahuguna
Default Save multiple rows at once.

Hello Friends,

I have to make an Interface in ASP.Net using C#. I have to take multiple rows at once maybe using Grid. I mean suppose user has to put 5 or more rows and in one click all row should be saved into database. Please advice what the way and server control should be best to do it.

Old November 24th, 2009, 08:50 AM
Friend of Wrox
Join Date: May 2006
Posts: 107
Thanks: 1
Thanked 8 Times in 7 Posts

Have a look at


Once you have identified the rows to be processed then you just need to develop the code to process them and save them.
Old November 27th, 2009, 03:31 AM
Authorized User
Join Date: Dec 2007
Posts: 59
Thanks: 9
Thanked 0 Times in 0 Posts

This below is the code that help you
<asp:GridView ID="GridViewFirst" DataKeyNames="AmenityID" runat="server" AutoGenerateColumns="False"
CellPadding="4" ForeColor="#333333" GridLines="None" Width="383px">
<FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<RowStyle BackColor="#EFF3FB" />


<input type="checkbox" id="chkAll1" onclick="Check(this,'(GridViewFirst)+')" />Check All
<asp:CheckBox ID="chkAddSelect" AutoPostBack="false" runat="server"
oncheckedchanged="chkAddSelect_CheckedChanged" />
<HeaderStyle HorizontalAlign="Left" VerticalAlign="Top" />
<ItemStyle HorizontalAlign="Left" VerticalAlign="Top" Width="100px" />
<asp:TemplateField HeaderText="Category Name">
<asp:Label ID="lblCategoryName" runat="server" Text='<%# Eval("AmenityName") %>' />
<HeaderStyle HorizontalAlign="Left" VerticalAlign="Top" />
<ItemStyle HorizontalAlign="Left" VerticalAlign="Top" />
<PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
<SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
<HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<EditRowStyle BackColor="#2461BF" />
<AlternatingRowStyle BackColor="White" />

code behind
Protected Sub btAddRow_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btAddAmenity.Click
If Page.IsPostBack = True Then
Dim idAs String = Request.QueryString("hid")
Dim strSql As New StringBuilder(String.Empty)
Dim con As New SqlConnection(clsCommons.GetConnStr)
Dim cmd As New SqlCommand()
For i As Integer = 0 To GridViewFirst.Rows.Count - 1
Dim chkUpdate As CheckBox = DirectCast(GridViewFirst.Rows(i).Cells(0).FindCont rol("chkAddSelect"), CheckBox)
' your gird GridViewFirst
If chkUpdate IsNot Nothing Then
If chkUpdate.Checked Then
Const strUpdate As String = "Insert Into table(A,B) Values(@AID,@BID)"
cmd.CommandType = CommandType.Text
cmd.CommandText = strUpdate.ToString()
cmd.Parameters.AddWithValue("@AID", HotelID)
cmd.Parameters.AddWithValue("@BID", strID)
cmd.Connection = con
Catch ex As SqlException
Dim errorMsg As String = "Error in addional ."
errorMsg += ex.Message
Throw New Exception(errorMsg)
End Try

End If
End If
End If
End Sub

Similar Threads
Thread Thread Starter Forum Replies Last Post
cannot show edited rows after a save greenbriar BOOK: Beginning Visual Basic 2005 Databases ISBN: 978-0-7645-8894-5 2 January 13th, 2009 04:22 PM
Read CSV file - Save Columns into Rows pintoo BOOK: Professional SQL Server 2005 Integration Services ISBN: 0-7645-8435-9 1 August 20th, 2008 09:01 AM
Copying Multiple Rows raj_phoenix Excel VBA 3 May 6th, 2005 03:58 AM
print multiple times..multiple rows... abhit_kumar JSP Basics 3 January 18th, 2005 07:11 PM
Updating multiple Rows from multiple fields in ASP vdm_nana SQL Server ASP 0 April 1st, 2004 04:26 AM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.