how to bind image in image button control from database in asp.net c#
In this article, we will bind the image button with image .Many time we
want to show profile pic so this code will be help you. In the previous article.
I have shown how to save the image in data base .So you can get the code for
that .here I will show only how to display (bind) the image with image button
control.
Fore more:-
Preview of image before upload using java script and JQuery , how to upload image save ,retrieve and delete it in asp.net c# ,How to save image in folder without using database and show in datalist in asp.net ,How to save image in data base and retrieve it on datalist in asp.net c#
Date base:-
Source Code:-
<%@
Page Language="C#" AutoEventWireup="true" CodeFile="imagebutton.aspx.cs" Inherits="imagebutton"
%>
<!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>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:ImageButton ID="ImageButton1" runat="server" BorderStyle="Dotted" ImageAlign="Middle"
Width="250px" />
</div>
</form>
</body>
</html>
Code Behind(c#):-
using System;
using
System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using
System.Web.UI.WebControls;
using
System.Data.SqlClient;
using System.Data;
public partial class imagebutton : System.Web.UI.Page
{
protected void Page_Load(object
sender, EventArgs e)
{
SqlConnection
con = new SqlConnection("Data Source=NEERAJ-PC;Initial Catalog=CodeSolution;Persist
Security Info=True;User ID=sa; password=12345678");
con.Open();
SqlCommand
cmdImageupload = new SqlCommand("Select * from image where id='3'",
con);
SqlDataAdapter
daImageupload = new SqlDataAdapter(cmdImageupload);
SqlDataAdapter
da = new SqlDataAdapter(cmdImageupload);
DataTable
dt = new DataTable();
da.Fill(dt);
string
url = dt.Rows[0][2].ToString();
ImageButton1.ImageUrl = url;
con.Close();
}
}
Out-Put:-
how to bind image in image button control from database in asp.net c#
Reviewed by NEERAJ SRIVASTAVA
on
7:14:00 PM
Rating:
No comments: