Solved

ASP.NET get values from datagrid on a previous page

Posted on 2010-11-30
10
519 Views
Last Modified: 2012-05-10
In the previous page in my web app I have a gridview with a checkbox column and values in the other columns. How do I get the values from the gridview in the previous page from the gridview? I figured I'd loop through the gridview in the previous page like below and ones that are checked I'd just grab those values and put them in my current page.
For Each row As GridViewRow In myGV.Rows
                    Dim cb As CheckBox = row.FindControl("mycheckbox")
                    If cb IsNot Nothing AndAlso cb.Checked Then
               
'do my stuff
end if

Open in new window

0
Comment
Question by:cobolinx1
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 5
10 Comments
 
LVL 11

Expert Comment

by:MajorBigDeal
ID: 34244833
Just to verify - you have a Gridview with AllowPaging turned on.  You are trying to access every row of the gridview, not just the current page but you are having a problem.  Is that correct?
0
 

Author Comment

by:cobolinx1
ID: 34257255
I turned allowpaging off. Pretty much I select rows by checking a checkbox column in the gridview and click a button so that I can go to a new page and display the ones that I checked.
0
 
LVL 11

Expert Comment

by:MajorBigDeal
ID: 34262195
OK, that makes sense.  So what are you using as your underlying datasource - is it a datatable?

Do you want to post your code?
0
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 
LVL 11

Accepted Solution

by:
MajorBigDeal earned 500 total points
ID: 34271641
So if you are only displaying selected records in your gridview then you can maintain the checked state for all the records elsewhere.  Here is an example of how to do that - hope it helps!

http://www.experts-exchange.com/Programming/Languages/.NET/Q_23117312.html
0
 

Author Comment

by:cobolinx1
ID: 34283407
Thanks for the example (250 points) that really helps....but how do I reference the datatable on that page when I goto the next page?
0
 

Author Comment

by:cobolinx1
ID: 34284278
Pretty much I was just binding the datagridview to a connection I already established. I took that example from above and grabbed data from the database then pretty much created a new datatable by reading in the table I already had to handle the itemstate but when I try and sort now it says it fired event Sorting which wasn't handled. Do I have to build that from scratch??


Below is the code that I had in my example that I created a new connection and bound the datagrid to it.
<asp:GridView ID="gvterm" runat="server" AllowSorting="True" 
                AutoGenerateColumns="False" BackColor="White" BorderColor="#000066" 
                BorderStyle="Solid" BorderWidth="1px" CellPadding="4" 
                DataSourceID="ORCCON" Width="775px">
                <RowStyle BackColor="White" ForeColor="#003399" />
                <Columns>
                    <asp:TemplateField HeaderText="Select">
                        <ItemTemplate>
                            <asp:CheckBox ID="Select" runat="server" />
                        </ItemTemplate>
                        <ControlStyle Font-Underline="False" />
                        <HeaderStyle Font-Underline="True" />
                    </asp:TemplateField>
                    <asp:BoundField DataField="EMPLOYEE_ID" DataFormatString="{0:F0}" 
                        HeaderText="EMPLOYEE_ID" ReadOnly="True" SortExpression="EMPLOYEE_ID" />
                    <asp:BoundField DataField="PFI" HeaderText="Employment" SortExpression="Employment" />
                    <asp:BoundField DataField="FIRST_NAME" HeaderText="FIRST_NAME" 
                        SortExpression="FIRST_NAME" />
                    <asp:BoundField DataField="LAST_NAME" HeaderText="LAST_NAME" 
                        SortExpression="LAST_NAME" />
                    <asp:BoundField DataField="DOB" DataFormatString="{0:d}" HeaderText="DOB" 
                        SortExpression="DOB" />
                </Columns>
                <FooterStyle BackColor="#99CCCC" ForeColor="#003399" />
                <PagerStyle BackColor="#99CCCC" ForeColor="#003399" HorizontalAlign="Left" />
                <SelectedRowStyle BackColor="#009999" Font-Bold="True" ForeColor="#CCFF99" />
                <HeaderStyle BackColor="#003399" Font-Bold="True" ForeColor="#CCCCFF" />
            </asp:GridView>
        </div>

Open in new window

0
 
LVL 11

Expert Comment

by:MajorBigDeal
ID: 34287174
Excellent - sounds like you are on track.  Yes, you have to build the sorting from scratch and it is a bit of a pain but there are lots of good examples of how to do this floating around.  I don't know why there isn't some kind of default implementation - maybe there is and I don't know about it!
0
 

Author Comment

by:cobolinx1
ID: 34294269
But is there a way to go to a new webpage like Server.Transfer("~/default2.aspx", True) and get the values from the datagrid on default.aspx?
0
 
LVL 11

Assisted Solution

by:MajorBigDeal
MajorBigDeal earned 500 total points
ID: 34295383
You can store the values in Context.Items and after the Server.Transfer that info will still be in Context.Items for you to access.  Also, you had mentioned that you were persisting using a DB so of course you could use that as well.
0
 

Author Closing Comment

by:cobolinx1
ID: 34301988
Perfect!!!!!! I'll loop through and store them as items then can call them back....Now I just need to figure out how to sort the checkbox field....but I guess thats a differant question.
0

Featured Post

Turn Insights Into Action

You’ve already invested in ITSM tools, chat applications, automation utilities, and more. Fortify these solutions with intelligent communications so you can drive business processes forward.

With xMatters, you'll never miss a beat.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In my previous article (http://www.experts-exchange.com/Programming/Languages/.NET/.NET_Framework_3.x/A_4362-Serialization-in-NET-1.html) we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

695 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question