I want to display gridview in horizontal format in C# and Vb.Net.
I want to display my image from the database in horizontal format but GridView does not allow what I want. How do I change my code to suit how I want my images to display.
ASPX
<asp:GridView ID="gvImages" runat="server" AutoGenerateColumns="false" OnRowDataBound="OnRowDataBound">
<Columns>
<asp:BoundField HeaderText="File Name" DataField="image_name" />
<asp:TemplateField HeaderText="image">
<ItemTemplate>
<asp:Image ID="Image1" runat="server" Height="80" Width="80" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
CS
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
this.BindGrid();
}
}
private void BindGrid()
{
MySqlConnection connection = new MySqlConnection(xxxxxxx)
using (MySqlCommand cmd = new MySqlCommand())
{
cmd.CommandText = "SELECT * FROM annexa_images";
cmd.Connection = connection;
using (MySqlDataAdapter dr = new MySqlDataAdapter(cmd))
{
DataTable dt = new DataTable();
dr.Fill(dt);
gvImages.DataSource = dt; //GridView ID
gvImages.DataBind(); //GridView ID
}
}
protected void OnRowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
byte[] bytes = (byte[])(e.Row.DataItem as DataRowView)["image"];
string base64String = Convert.ToBase64String(bytes, 0, bytes.Length);
(e.Row.FindControl("Image1") as Image).ImageUrl = "data:image/png;base64," + base64String;
}
}