Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 3.5 > ASP.NET 3.5 Professionals
Password Reminder
Register
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
 
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old October 30th, 2009, 06:01 AM
Friend of Wrox
 
Join Date: Jan 2006
Location: Hardwar, Uttranchal, India.
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.


Thanks!
Cheers!!
__________________
DPK..
  #2 (permalink)  
Old November 24th, 2009, 08:50 AM
Friend of Wrox
 
Join Date: May 2006
Location: Northampton, United Kingdom.
Posts: 107
Thanks: 1
Thanked 8 Times in 7 Posts
Default

Have a look at

http://www.codeproject.com/KB/webfor...aGridView.aspx

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

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" />
<Columns>
<asp:TemplateField>

<HeaderTemplate>

<input type="checkbox" id="chkAll1" onclick="Check(this,'(GridViewFirst)+')" />Check All
</HeaderTemplate>
<ItemTemplate>
<asp:CheckBox ID="chkAddSelect" AutoPostBack="false" runat="server"
oncheckedchanged="chkAddSelect_CheckedChanged" />
</ItemTemplate>
<HeaderStyle HorizontalAlign="Left" VerticalAlign="Top" />
<ItemStyle HorizontalAlign="Left" VerticalAlign="Top" Width="100px" />
</asp:TemplateField>
<asp:TemplateField HeaderText="Category Name">
<ItemTemplate>
<asp:Label ID="lblCategoryName" runat="server" Text='<%# Eval("AmenityName") %>' />
</ItemTemplate>
<HeaderStyle HorizontalAlign="Left" VerticalAlign="Top" />
<ItemStyle HorizontalAlign="Left" VerticalAlign="Top" />
</asp:TemplateField>
</Columns>
<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" />
</asp:GridView>



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
Try
Const strUpdate As String = "Insert Into table(A,B) Values(@AID,@BID)"
cmd.CommandType = CommandType.Text
cmd.CommandText = strUpdate.ToString()
cmd.Parameters.Clear()
cmd.Parameters.AddWithValue("@AID", HotelID)
cmd.Parameters.AddWithValue("@BID", strID)
cmd.Connection = con
con.Open()
cmd.ExecuteNonQuery()
Catch ex As SqlException
Dim errorMsg As String = "Error in addional ."
errorMsg += ex.Message
Throw New Exception(errorMsg)
Finally
con.Close()
End Try

End If
End If
Next
End If
End Sub
 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 09:12 PM.


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