Hello sir,
How to display image dynamically from database?
thank u.
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Munesh SharmaPosted Mar 24, 2014, 1:37 AM
<asp:GridView ID="GridView2" runat="server" AutoGenerateColumns = "false"
Font-Names = "Arial" Caption = "Using ImageControl" >
<Columns>
<asp:BoundField DataField = "ID" HeaderText = "ID" />
<asp:BoundField DataField = "name" HeaderText = "Name" />
<asp:BoundField DataField = "FatherName" HeaderText = "FatherName" />
<asp:BoundField DataField = "image" HeaderText = "Image Name" />
<asp:TemplateField>
<ItemTemplate>
<asp:Image ID="Image1" Height = "100" Width = "100" runat="server"
ImageUrl = '' />
ItemTemplate>
asp:TemplateField>
Columns>
asp:GridView>
ON Page Load_event..
protected void Page_Load(object sender, EventArgs e)
{
DataTable dt = new DataTable();
String strConnString = System.Configuration.ConfigurationManager.
ConnectionStrings["conString"].ConnectionString;
string strQuery = "select ID, Name,iamgename,fathername from tblFiles order by ID";
SqlCommand cmd = new SqlCommand(strQuery);
SqlConnection con = new SqlConnection(strConnString);
SqlDataAdapter sda = new SqlDataAdapter();
cmd.CommandType = CommandType.Text;
cmd.Connection = con;
try
{
con.Open();
sda.SelectCommand = cmd;
sda.Fill(dt);
GridView1.DataSource = dt;
GridView1.DataBind();
GridView2.DataSource = dt;
GridView2.DataBind();
}
catch (Exception ex)
{
Response.Write(ex.Message);
}
finally
{
con.Close();
sda.Dispose();
con.Dispose();
dt.Dispose();
}
}