Sample.aspx
<div id="login">
<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='Photo/<%#Eval("Photo")%>' height="50px" width="50px" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
Sample.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());
}
}
DataBase:
EmpID PrimaryKet(1,1)
UName varchar(50),
Password varchar(50),
Photo image
Getting an ERROR: The User photo not displaying