Solved

asp.net show selected gridview data in 2nd area on page

Posted on 2013-01-02
5
586 Views
Last Modified: 2013-01-04
Hi Experts,

I currently have a gridview that shows information from a db2 database, the SQL is a little messy but given how I have been asked to pull the data it works and will be refined shortly..

The new requriement is that the data is selectable and the selected data shows in a second area.

The way this has been laid out in the spec shows that is must not be a second gridview, but more a table with textfields

the code used to bind the data to the gridview is

 txtSuName.Text = txtSuName.Text.ToUpper
        'If txtSuName.Text.Length = 0 And txtSupNo.Text.Length = 0 And drp20.SelectedValue = "" And drp21.SelectedValue = "" And drp22.SelectedValue = "" And drp23.SelectedValue = "" And drp23.SelectedValue = "" Then
        If txtSuName.Text.Length = 0 And drp20.SelectedValue = "" And drp21.SelectedValue = "" And drp22.SelectedValue = "" Then
            Exit Sub

        End If

        Dim supNo, supName, cat20, cat21, cat22 As String
        If rdoSupName.SelectedValue = "Name" Then
            If txtSuName.Text = Nothing Then
                supName = Nothing
            Else
                supName = "and a.ABALPH like '%" & txtSuName.Text & "%'"
            End If
        End If

        If rdoSupName.SelectedValue = "Number" Then
            If txtSuName.Text = Nothing Then
                supNo = Nothing
            Else
                supNo = "and a.ABAN8 like '%" & txtSuName.Text & "%'"
            End If
        End If

        If drp20.SelectedValue = Nothing Then
            cat20 = Nothing
        Else
            cat20 = " and b.drdl01ac20 = '" & drp20.SelectedValue & "'"
        End If

        If drp21.SelectedValue = Nothing Then
            cat21 = Nothing
        Else
            cat21 = "and c.drdl01ac21 = '" & drp21.SelectedValue & "'"
        End If

        If drp22.SelectedValue = Nothing Then
            cat22 = Nothing
        Else
            cat22 = "and d.drdl01ac22 = '" & drp22.SelectedValue & "'"
        End If

                sqlstr = "select distinct a.ABAN8 as Number, a.ABALPH as Name, a.ABAT1 as Type, g.aladdz as PostCode, " & _
        "b.drkyac20 as Level_1, b.drdl01ac20 as Level_1_Description,  " & _
        "c.drkyac21 as Level_2, c.drdl01ac21 as Level_2_Description,  " & _
        "d.drkyac22 as Level_3, d.drdl01ac22 as Level_3_Description,  " & _
        "g.aladd2 as Address, g.aladd3 as Address, g.aladd4 as Address, g.alcty1 as City, g.alcoun as County, g.alctr as Country " & _
        "FROM TRDTA.F0101 as a,  trdta.f0005_ac20 as b, trdta.f0005_ac21 as c, trdta.f0005_ac22 as d, trdta.f0005_ac23 as e, trdta.f0005_ac24 as f, trdta.f0116 as g  " & _
        "where ABAT1 IN ('V', 'VF', 'VM', 'VH') " & _
        "and trim(a.abac20) = trim(b.drkyac20) " & _
        "and trim(a.abac21) = trim(c.drkyac21) " & _
        "and trim(a.abac22) = trim(d.drkyac22) " & _
        "and a.aban8 = g.alan8 " & _
supNo & _
    supName & _
    cat20 & _
    cat21 & _
    cat22


        sqlconn.ConnectionString = connstr
        sqlconn.Open()
        sqlcmd.Connection = sqlconn

        sqlcmd.CommandText = sqlstr

        sqldr = sqlcmd.ExecuteReader


        GridView1.DataSource = sqldr
        GridView1.DataBind()
        sqldr.Close()
        sqlconn.Close()

Open in new window


This is the gridview as is currently stands...

 <asp:GridView ID="GridView1" runat="server" CellPadding="4" 
                EnableModelValidation="True" ForeColor="#333333" GridLines="None" 
                AllowPaging="false">

                 <Columns>
                    <asp:CommandField ShowSelectButton="True" />
                <%--    <asp:TemplateField>            
                    <ItemTemplate>                
                    <asp:CheckBox ID="chkSel" runat="server" />            
                    </ItemTemplate>        
                    </asp:TemplateField>--%>
                                       
                </Columns>

            <AlternatingRowStyle BackColor="White" />
            <EditRowStyle BackColor="#2461BF" />
            <FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
            <HeaderStyle BackColor="#507CD1" Font-Bold="False" ForeColor="White" Font-Size="12px" Font-Names="Arial" />
            <PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
            <RowStyle BackColor="#EFF3FB" Font-Size="12px" Font-Names="Arial" />
            <SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
        </asp:GridView>

Open in new window


Any and all help very much appreciated.

thanks

Simon
0
Comment
Question by:SimonPrice33
[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
  • 3
5 Comments
 
LVL 39

Accepted Solution

by:
Pratima Pharande earned 500 total points
ID: 38735868
I think you need somethin similar to this tutorial

xplaining how to add or remove selected rows from one ASP.Net GridView Control to another in other words copying selected rows to another ASP.Net GridView Control and  removing unselected rows from the another ASP.Net GridView Control

Concept

The concept behind this tutorial is to use a temporary DataTable to maintain the list selected rows or records and then use the DataTable to bind the secondary GridView
refer
http://www.aspsnippets.com/Articles/Transfer-Selected-Rows-from-one-GridView-to-Another-in-Asp.net.aspx
0
 

Author Comment

by:SimonPrice33
ID: 38735875
I have seen this but this looks like it is using bound datafields,

i would like to user this example, but cannot for the life of me seem to bind the datafields in the gridview. If you could help me with that I would be most grateful and could use this as the solution.

thanks

Simon
0
 

Author Comment

by:SimonPrice33
ID: 38736064
trying to use bound fields i get this error

SQL0104 Token . was not valid. Valid tokens: , FROM INTO.

any suggestions?
0
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 38738302
0
 

Author Closing Comment

by:SimonPrice33
ID: 38743306
Although not a full answer, it has helped my find my solution :)
0

Featured Post

Webinar: Aligning, Automating, Winning

Join Dan Russo, Senior Manager of Operations Intelligence, for an in-depth discussion on how Dealertrack, leading provider of integrated digital solutions for the automotive industry, transformed their DevOps processes to increase collaboration and move with greater velocity.

Question has a verified solution.

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

Suggested Solutions

Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

749 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