hi,
Can i add images dynamically from database in img tag without using any upload button,i want to load images in img tag on page_load, so how can i do..? suppose there are 3 images in database and they must be added on img tag respectively while page will load...
I have code like...
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="div.aspx.cs" Inherits="User_Images_div" %>
<%@ Import Namespace="System.Data.SqlClient" %>
<%@ Import Namespace="System.Data" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<link href="Styles/StyleSheet.css" rel="stylesheet" type="text/css" />
<script runat="server">
SqlConnection cn = new SqlConnection("Data Source=COMPUTER;Initial Catalog=demo_page;Integrated Security=True");
SqlCommand cmd;
SqlDataReader dr;
DataSet ds;
SqlDataAdapter adp;
int j;
static string str;
public int getCount()
{
cn.Open();
string qry = "select count(id) from Image";
cmd = new SqlCommand(qry, cn);
dr = cmd.ExecuteReader();
while (dr.Read())
{
j = (int)dr[0];
}
cn.Close();
return j;
}
public string getImgUrl()
{
cn.Open();
cmd = new SqlCommand("select img_url from Image",cn);
string qry = "select img_url from Image";
adp = new SqlDataAdapter(qry, cn);
ds = new DataSet();
adp.Fill(ds);
for (int i = 0; i < getCount(); i++)
{
str = ds.Tables[0].Rows[i]["img_url"].ToString();
}
cn.Close();
return str;
}
</script>
</head>
<body>
<form id="form1" runat="server">
<% int c = getCount(); %>
<table cellpadding="0" cellspacing="0" style="width: 100%">
<%for (int i = 0; i < c; i++){
%>
<tr>
<% for (int j = 0; j < 3; j++)
{ str = getImgUrl();
%>
<td>
<div class="prod_box">
<div class="top_prod_box"></div>
<div class="center_prod_box">
<div class="product_title"></div>
<div class="product_img">
<asp:Image ID="Image1" ImageUrl='<%=str %>' Width="146px" Height="73px" runat="server" />
<%--<img src=<%#str%> alt="" />--%></div></div>
<div class="bottom_prod_box"></div>
<div class="prod_details_tab" align="center"></div>
</div>
</td>
<% } %>
</tr>
<% } %>
</table>
</form>
</body>
</html>
plz help me..
thank u..........