Image gallery with DataGrid

Discussion in 'ASP .Net' started by =?Utf-8?B?bHR0MTk=?=, Jun 14, 2005.

  1. Hi everyone!

    I want to do da Image gallery using just the datagrid, this one will dilpays
    only images, no text, that means that it will have about 4 Collumns that will
    displays just images from the same database table, from the same collumn of
    the table. However I could not reproduce this, since each Row (with 4
    collumns) displays 4 times the same image. How can i fix it?

    here is a part of the code:

    <Columns>
    <asp:TemplateColumn>
    <ItemTemplate>
    <asp:Image Runat='server' ID='thumb' Width='140' Height='110' ImageUrl='<%#
    DataBinder.Eval(Container.DataItem, "path") %'></asp:Image>
    <asp:Image Runat='server' ID="Image1" Width='140' Height='110' ImageUrl='<%#
    DataBinder.Eval(Container.DataItem, "path") %'></asp:Image>
    <asp:Image Runat='server' ID="Image2" Width='140' Height='110' ImageUrl='<%#
    DataBinder.Eval(Container.DataItem, "path") %'></asp:Image>
    <asp:Image Runat='server' ID="Image3" Width='140' Height='110' ImageUrl='<%#
    DataBinder.Eval(Container.DataItem, "path") %'></asp:Image>
    </ItemTemplate>
    </asp:TemplateColumn>
    </Columns>

    Just not to post other topic: The datasource of this datagrid is "created"
    when the user clicks on the button of an Album. Since an Album can contains
    many photos, I'll use paging in this datagrid, however when I click on the
    pagers, the datagrid disspears.

    Code:

    Dim cm As New Data.OleDb.OleDbDataAdapter("SELECT id, [path],[desc] FROM
    fotos WHERE [album]=?", cn)
    '' Dim ds As New Data.DataSet
    cm.SelectCommand.Parameters.Add("album", ddlAlbum.SelectedValue)
    ds.Clear()
    cn.Open()
    cm.Fill(ds)
    cn.Close()
    ' Stop
    dgImg.DataSource = ds
    dgImg.DataBind()

    The PageIndexChanged event is also done:
    If e.NewPageIndex >= 0 Then
    dgImg.CurrentPageIndex = e.NewPageIndex
    dgImg.DataBind()
    End If


    Any help would be very apprecciated.

    Thanks in advance
    =?Utf-8?B?bHR0MTk=?=, Jun 14, 2005
    #1
    1. Advertising

  2. Hi there,

    In order to page datagrid, you have to rebind the datagrid's data source.

    dgImg.CurrentPageIndex = e.NewPageIndex
    dgImg.DataSource = ds
    dgImg.DataBind()

    The ds can be got either by requering DB, or in the first query to save ds
    in Session, then retrieve it from Session.

    If you have more questions, please let us know.

    HTH

    Elton Wang





    "ltt19" wrote:

    > Hi everyone!
    >
    > I want to do da Image gallery using just the datagrid, this one will dilpays
    > only images, no text, that means that it will have about 4 Collumns that will
    > displays just images from the same database table, from the same collumn of
    > the table. However I could not reproduce this, since each Row (with 4
    > collumns) displays 4 times the same image. How can i fix it?
    >
    > here is a part of the code:
    >
    > <Columns>
    > <asp:TemplateColumn>
    > <ItemTemplate>
    > <asp:Image Runat='server' ID='thumb' Width='140' Height='110' ImageUrl='<%#
    > DataBinder.Eval(Container.DataItem, "path") %'></asp:Image>
    > <asp:Image Runat='server' ID="Image1" Width='140' Height='110' ImageUrl='<%#
    > DataBinder.Eval(Container.DataItem, "path") %'></asp:Image>
    > <asp:Image Runat='server' ID="Image2" Width='140' Height='110' ImageUrl='<%#
    > DataBinder.Eval(Container.DataItem, "path") %'></asp:Image>
    > <asp:Image Runat='server' ID="Image3" Width='140' Height='110' ImageUrl='<%#
    > DataBinder.Eval(Container.DataItem, "path") %'></asp:Image>
    > </ItemTemplate>
    > </asp:TemplateColumn>
    > </Columns>
    >
    > Just not to post other topic: The datasource of this datagrid is "created"
    > when the user clicks on the button of an Album. Since an Album can contains
    > many photos, I'll use paging in this datagrid, however when I click on the
    > pagers, the datagrid disspears.
    >
    > Code:
    >
    > Dim cm As New Data.OleDb.OleDbDataAdapter("SELECT id, [path],[desc] FROM
    > fotos WHERE [album]=?", cn)
    > '' Dim ds As New Data.DataSet
    > cm.SelectCommand.Parameters.Add("album", ddlAlbum.SelectedValue)
    > ds.Clear()
    > cn.Open()
    > cm.Fill(ds)
    > cn.Close()
    > ' Stop
    > dgImg.DataSource = ds
    > dgImg.DataBind()
    >
    > The PageIndexChanged event is also done:
    > If e.NewPageIndex >= 0 Then
    > dgImg.CurrentPageIndex = e.NewPageIndex
    > dgImg.DataBind()
    > End If
    >
    >
    > Any help would be very apprecciated.
    >
    > Thanks in advance
    =?Utf-8?B?RWx0b24gVw==?=, Jun 14, 2005
    #2
    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. news.microsoft.com
    Replies:
    1
    Views:
    826
    fd123456
    Feb 27, 2005
  2. Dougbert
    Replies:
    0
    Views:
    312
    Dougbert
    Sep 28, 2005
  3. www.web20developers.com
    Replies:
    0
    Views:
    576
    www.web20developers.com
    Oct 12, 2006
  4. KiwiBrian

    Image gallery query

    KiwiBrian, Apr 30, 2007, in forum: HTML
    Replies:
    2
    Views:
    412
    Neredbojias
    May 1, 2007
  5. Lorenzo Bolognini

    [Maybe OT] Image gallery generator

    Lorenzo Bolognini, Sep 26, 2003, in forum: ASP General
    Replies:
    5
    Views:
    225
    James Monroe
    Sep 27, 2003
Loading...

Share This Page