Do not use on any
shared computer
August 29, 2008 10:11pm pdt
 
[x]
Attachment Details

How do you select rows from one gridview to populate another gridview on a different page?

Tags: another, populate, select
Hi All,

There have been some questions asked about his but am still unsure how to apply to my situation. Basically..

Using Visual Web developer 2005 (VB.Net),

I have a database  table (SQL Server Express 2005) called Contact that has ContactID, FirstName, LastName, Company and Email for columns. ContactID is the primary key.

I have a aspx page called searchresults that has a gridview to show the contact data. (ContactID is not included in the gridview) There are checkboxes next to each row done using asp like this
<ItemTemplate>
             <asp:CheckBox ID="chkSelect" runat="server"  />
</ItemTemplate>

The data itself is generated using code like this...

    Public Function generatedata(ByVal conn As String, ByVal query As String) As DataTable

        Dim connection As New SqlConnection(conn)
        Dim command As New SqlCommand
        command.Connection = connection
        command.CommandType = CommandType.Text
        command.CommandText = query
        Dim adapter As New SqlDataAdapter(command)
        Dim buffer As New DataTable

        adapter.Fill(buffer)

        Return buffer
    End Function


    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Dim conn_string, query As String
        Dim results As New DataTable

        conn_string = "Data Source=.\SQLEXPRESS;AttachDbFilename=" & "C:\Documents and Settings\mk\My Documents\Visual Studio 2005\WebSites\Contacts\App_Data\Contacts.mdf" & ";Integrated Security=True;Connect Timeout=30;User Instance=True"

'although this is a search results page, this query is used to populate the gridview with data for 'development purposes, the search function has not been implemented yet
        query = "select FirstName As [First Name], LastName As [Last Name], Email from Contact WHERE ContactID<150"

        results = generatedata(conn_string, query)

        GridView1.DataSource = results
        GridView1.DataBind()
    End Sub

What I want to do is select the rows I am interested in, click a button, go to a different page such as details.aspx and fill the gridview with the rows I have selected.

My coding ability in all honesty is not that great I am only just about getting to grips with vb.net, I would really appreciate it if anyone could show us how this could be done. I'll be manipulating the data in the gridviews in certain ways which isn't really that important at this moment in time - so long as I can understand how to get data from gridview to gridview on different pages I think I should be able to manage. My apologies about the length of this question.
Start your free trial to view this solution
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

Question Stats
Zone: Programming
Question Asked By: strictly_mk
Solution Provided By: Svetlin_Panayotov
Participating Experts: 1
Solution Grade: A
Views: 21
Translate:
Loading Advertisement...
 
[+][-]Accepted Solution by Svetlin_Panayotov
Accepted Solution by Svetlin_Panayotov:

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
[+][-]Author Comment by strictly_mk
Author Comment by strictly_mk:

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
[+][-]Expert Comment by Svetlin_Panayotov
Expert Comment by Svetlin_Panayotov:

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
Loading Advertisement...
20080723-EE-VQP-34 / EE_QW_1_20070628