TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Deepak Ratan
NA
175
50.6k
how to display image from sql table in gridview?
May 19 2015 8:32 AM
hi i tried to display image from sql table to gridview but its not displaying this s my code to bind gridview with sql table records..
sql.aspx.cs
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
lblsession.Text = "Welcome" + Convert.ToString(Session["UName"]);
sessionimage();
}
}
private void sessionimage()
{
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["connect"].ConnectionString);
try
{
string UName = (string)Session["UName"];
SqlDataAdapter Adp = new SqlDataAdapter("select Photo from TBL_PBLogin where UName='"+ UName +"'", con);
DataTable Dt = new DataTable();
con.Open();
Adp.Fill(Dt);
gridviewphoto.DataSource = Dt;
gridviewphoto.DataBind();
con.Close();
}
catch (Exception ex)
{
throw new Exception(ex.ToString());
}
}
sql.aspx
<div>
<asp:Label ID="lblsession" runat="server" ForeColor="white" CssClass="label"></asp:Label>
<asp:GridView ID="gridviewphoto" runat="server" AutoGenerateColumns="false" BackColor="#CC3300" ForeColor="Black" ShowHeader="false" GridLines="None">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<img alt="" src='<%#Eval("Photo")%>' height="50px" width="50px" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</div>
Reply
Answers (
45
)
Is Performance hit :- caling javascript in OnPreRender.?
upload and feedback