Populating a Datagrid

Discussion in 'ASP .Net Web Controls' started by Lee, Jan 21, 2004.

  1. Lee

    Lee Guest

    Hi All,

    I have a webform with a datagrid on it. The only way I have been able to
    find to populate it, would be to bind it to a datacontrol dropped on the
    same page.

    The issue I have is, that all of our data access is done from a seperate
    class so that it is in one place and I'd like to keep it that way and don't
    want to have SQL calls from any of the webpage control directly.

    I have been able to pass a recordset back to the webpage, but cant figure
    out how I would populate the datagrid with it. Does anyone know if this can
    be done?

    Thanks

    Lee Trotter
    Lee, Jan 21, 2004
    #1
    1. Advertising

  2. Lee

    Gerald Klein Guest

    WHat do you mean by recordset? Old ASP? You can use anything that implements
    ICollection as a datasource


    "Lee" <> wrote in message
    news:...
    > Hi All,
    >
    > I have a webform with a datagrid on it. The only way I have been able to
    > find to populate it, would be to bind it to a datacontrol dropped on the
    > same page.
    >
    > The issue I have is, that all of our data access is done from a seperate
    > class so that it is in one place and I'd like to keep it that way and

    don't
    > want to have SQL calls from any of the webpage control directly.
    >
    > I have been able to pass a recordset back to the webpage, but cant figure
    > out how I would populate the datagrid with it. Does anyone know if this

    can
    > be done?
    >
    > Thanks
    >
    > Lee Trotter
    >
    >
    Gerald Klein, Jan 21, 2004
    #2
    1. Advertising

  3. Lee

    ONIL@ Guest

    Hi Lee !

    You can use a DataTable like this :

    Dim dt As DataTable

    Dim dr As DataRow

    Dim i As Integer

    'create a DataTable

    dt = New DataTable

    dt.Columns.Add(New DataColumn("Name", GetType(String)))

    dt.Columns.Add(New DataColumn("First.", GetType(String)))

    dt.Columns.Add(New DataColumn("Last", GetType(String)))

    'Make the rows and add data.

    For i = 1 To 12

    dr = dt.NewRow()

    dr(0)= "Hi " & i+1
    dr(1) = "Hi" & i+2


    dr(2) = "Hi" & i+3

    'add each row to the DATATABLE

    dt.Rows.Add(dr)

    Next

    dr = dt.NewRow()

    dt.Rows.Add(dr)

    DataGrid1.DataSource = new DataView(dt)

    DataGrid1.DataBind

    I hope it helps
    Best Regards
    --
    ONil@.
    MX.

    "Lee" <> wrote in message
    news:...
    > Hi All,
    >
    > I have a webform with a datagrid on it. The only way I have been able to
    > find to populate it, would be to bind it to a datacontrol dropped on the
    > same page.
    >
    > The issue I have is, that all of our data access is done from a seperate
    > class so that it is in one place and I'd like to keep it that way and

    don't
    > want to have SQL calls from any of the webpage control directly.
    >
    > I have been able to pass a recordset back to the webpage, but cant figure
    > out how I would populate the datagrid with it. Does anyone know if this

    can
    > be done?
    >
    > Thanks
    >
    > Lee Trotter
    >
    >
    ONIL@, Jan 22, 2004
    #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. John
    Replies:
    1
    Views:
    375
  2. Paul

    Timeout on populating a datagrid

    Paul, May 5, 2004, in forum: ASP .Net
    Replies:
    4
    Views:
    2,880
    Scott Allen
    May 5, 2004
  3. =?Utf-8?B?VGltOjouLg==?=

    Datagrid Dropdown not populating

    =?Utf-8?B?VGltOjouLg==?=, Aug 20, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    371
  4. Prime
    Replies:
    2
    Views:
    1,629
    Prime
    Oct 1, 2004
  5. Bob Hollness

    Populating a DataGrid

    Bob Hollness, Jan 12, 2005, in forum: ASP .Net
    Replies:
    4
    Views:
    2,482
    =?Utf-8?B?c2FyYQ==?=
    Jan 12, 2005
Loading...

Share This Page