i have a gallery in gridview that show pictures from database.
I need to show the gridview in horizontal layout.
Right now the pictures are organized from up to down, How can i change the gridview so it will show the pictures from left to right in one row ?
html code:
<asp:GridView ID="GridView3" class="GridView1" runat="server" Width="400px" AutoGenerateColumns="False" Height="90px"
CellPadding="4" GridLines="Horizontal">
<Columns>
<asp:ImageField DataImageUrlField="Image_path" DataImageUrlFormatString="~/Pic/{0}" HeaderText="Images">
<ControlStyle Height="100px" Width="100px" />
</asp:ImageField>
</Columns>
</asp:GridView>
c# code:
con.Open();
cmd = new SqlCommand("select image_path from tblImages", con);
da = new SqlDataAdapter(cmd);
dt = new DataTable();
da.Fill(dt);
GridView3.DataSource = dt;
GridView3.DataBind();
con.Close();
Use a DataList with RepeatDirection horizontal instead.
That works since you want to show a single column anyway.
<asp:DataList id="Images"
RepeatDirection="Horizontal"
RepeatLayout="Table"
RepeatColumns="0" runat="server">
<HeaderStyle BackColor="#aaaadd">
</HeaderStyle>
<AlternatingItemStyle BackColor="Gainsboro">
</AlternatingItemStyle>
<HeaderTemplate>
Images ...
</HeaderTemplate>
<ItemTemplate>
<asp:Image id="ProductImage"
AlternatingText='<%# DataBinder.Eval(Container.DataItem, "StringValue") %>'
ImageUrl='<%# Eval("image_path","~/Images/{0}") %>' />
runat="server"/>
</ItemTemplate>
</asp:DataList>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With