Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Asp.net gridview horizontal layout

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();

like image 636
Gilad Adar Avatar asked Jul 30 '26 13:07

Gilad Adar


1 Answers

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>
like image 116
Tim Schmelter Avatar answered Aug 01 '26 01:08

Tim Schmelter