Image gallery with DataGrid

G

Guest

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
 
G

Guest

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
(e-mail address removed)
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top