Retireve data with SqlDatasource & dynamically manipulate before dispalying

Discussion in 'ASP .Net Web Controls' started by collinsd@thewinesociety.com, Jul 19, 2006.

  1. Guest

    Hi

    I have a sqlDataSource control which currently populates a gridview.
    No problems with that. However I would like to populate an array with
    the data from the sqlDataSource and then manipulate the data, creating
    extra fields based upon the data within each row. I would then
    populate the gridview with the adjusted data from my array. I assume
    this could be done in VB in the on-load method for the page.

    However I can see no way of getting the data out of the sqlDataSource
    into an array - can anybody advise how this can be done or do I have to
    learn what appears to be a tortuous process of connecting to the
    database via VB?

    Many thanks for any help

    DC
     
    , Jul 19, 2006
    #1
    1. Advertising

  2. Guest

    Update on above message

    I have been able to get the data from the sqlDataSource into an array
    but cannot now get the databack onto the gridview so help in this area
    would be useful.

    Many Thanks

    DC

    > Hi
    >
    > I have a sqlDataSource control which currently populates a gridview.
    > No problems with that. However I would like to populate an array with
    > the data from the sqlDataSource and then manipulate the data, creating
    > extra fields based upon the data within each row. I would then
    > populate the gridview with the adjusted data from my array. I assume
    > this could be done in VB in the on-load method for the page.
    >
    > However I can see no way of getting the data out of the sqlDataSource
    > into an array - can anybody advise how this can be done or do I have to
    > learn what appears to be a tortuous process of connecting to the
    > database via VB?
    >
    > Many thanks for any help
    >
    > DC
     
    , Jul 20, 2006
    #2
    1. Advertising

  3. hi, try the following code. i just do something basic, like adding some more
    additional rows to the existing data
    returned by the sqldatasource control. You wanted to add some columns, i
    have included a reference on msdn along with the code below. It should help
    you move forward.

    Regards,
    Alessandro Zifiglio
    http://www.AsyncUI.net


    <%@ Page Language="VB" Debug="true"%>
    <%@ Import Namespace="System.Data" %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

    <script runat="server">
    Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
    'The sqlDataSrouce returns a DataView
    ' Currently returning one column with a list of topics from the
    topics table
    ' in database MyDatabase1.
    Dim dv As DataView =
    SqlDataSource1.Select(DataSourceSelectArguments.Empty)
    'Retrieve the DataTable, which should contain the data from our
    sqldatasource
    Dim table As DataTable = dv.Table()
    ' now lets populate DataTable, by adding 5 more extra rows to our
    existing data.
    ' you can add some more columns and do some other stuff, but lets
    keep it simple
    ' For more info on how to manipulate data in DataView.Table, you can
    reference
    ' the following document on msdn.
    '
    http://msdn2.microsoft.com/en-us/library/system.data.dataview.table.aspx

    Dim id As Integer
    For id = 1 To 5
    ' start adding rows to our DataTable.
    table.Rows.Add(New Object() {String.Format("New Topic {0}",
    id)})
    Next id
    Dim view As DataView = New DataView(table)
    GridView1.DataSource = view
    GridView1.DataBind()
    ' OR just render the values in our DataTable directly into our
    webpage
    ' by commenting out the following line.
    'PrintTable(view.Table, "DataTable")

    End Sub 'Page_Load

    Private Sub PrintTable(ByVal table As DataTable, ByVal label As String)
    ' This function prints values in the table or DataView.
    Response.Write("<br />" + label)
    Dim row As DataRow
    Dim column As DataColumn
    For Each row In table.Rows
    For Each column In table.Columns
    Response.Write("<br /> table " & row(column))
    Next column
    Next row
    End Sub

    </script>

    <html xmlns="http://www.w3.org/1999/xhtml" >
    <head runat="server">
    <title>Untitled Page</title>
    </head>
    <body>
    <form id="form1" runat="server">
    <div>
    <asp:SqlDataSource ID="SqlDataSource1" runat="server"
    ConnectionString="<%$ ConnectionStrings:MyConnectionString %>"
    SelectCommand="SELECT [Topic_TopicName] FROM
    [MyDatabase1_Topic]">
    </asp:SqlDataSource>
    <asp:GridView ID="GridView1" runat="server">
    </asp:GridView>

    </div>
    </form>
    </body>
    </html>

    <> ha scritto nel messaggio
    news:...
    > Update on above message
    >
    > I have been able to get the data from the sqlDataSource into an array
    > but cannot now get the databack onto the gridview so help in this area
    > would be useful.
    >
    > Many Thanks
    >
    > DC
    >
    >> Hi
    >>
    >> I have a sqlDataSource control which currently populates a gridview.
    >> No problems with that. However I would like to populate an array with
    >> the data from the sqlDataSource and then manipulate the data, creating
    >> extra fields based upon the data within each row. I would then
    >> populate the gridview with the adjusted data from my array. I assume
    >> this could be done in VB in the on-load method for the page.
    >>
    >> However I can see no way of getting the data out of the sqlDataSource
    >> into an array - can anybody advise how this can be done or do I have to
    >> learn what appears to be a tortuous process of connecting to the
    >> database via VB?
    >>
    >> Many thanks for any help
    >>
    >> DC

    >
     
    Alessandro Zifiglio, Jul 20, 2006
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Guest

    Dispalying asp pages

    Guest, Mar 31, 2006, in forum: ASP .Net
    Replies:
    10
    Views:
    696
    Nicolas Noakes
    Apr 19, 2006
  2. ...D.
    Replies:
    44
    Views:
    1,237
    SpaceGirl
    Jul 26, 2004
  3. Dave
    Replies:
    1
    Views:
    341
    Mike Wahler
    Jan 22, 2005
  4. Javier
    Replies:
    1
    Views:
    333
    red floyd
    Feb 8, 2005
  5. =?Utf-8?B?TWlrZQ==?=

    Dispalying data in a cell in gridview

    =?Utf-8?B?TWlrZQ==?=, Aug 28, 2007, in forum: ASP .Net
    Replies:
    2
    Views:
    471
Loading...

Share This Page