4
Answers

Ajax bind images from folder to image controls of datalist?

Photo of Dawood Abbas

Dawood Abbas

9y
372
1
How to bind images from application's folder  (which name come from databse) to image controls of datalist item template?
 
I tried like below
 
/*asp.net */
 
<asp:DataList ID="dlImages" runat="server" RepeatColumns="6">
<ItemTemplate>
<a id="imageLink" href='<%# Eval("ImageName","~/images/fabrics/{0}") %>' title='<%#Eval("Descript") %>' rel="lightbox[Brussels]" runat="server" >
<asp:Image ID="Image1" ImageUrl='<%# Bind("ImageName", "~/images/fabrics/{0}") %>' runat="server" Width="100px" Height="60px" hspace="20px"/><br />
<asp:Label ID="lbl1" runat="server" Text='<%#Eval("ImageAssignedName") %>' Height="30px"></asp:Label>
</a>
</ItemTemplate>
<ItemStyle HorizontalAlign="Center" VerticalAlign="Bottom"/>
</asp:DataList>
 
/*Jquery Ajax call */ 
 
<script type="text/javascript">
$(document).ready(function () {
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
url: "WebForm2.aspx/BindDatatable",
data: "{}",
dataType: "json",
success: function (data) {
alert('Hello 1');
for (var i = 0; i < data.d.length; i++) {
alert(data.d[i].ImageAssignedName);
$("#dlImages").append(data.d[i].ImageName + data.d[i].Descript + data.d[i].ImageAssignedName);
}
},
error: function (result) {
alert("Error");
}
});
});
</script>
 
 
/*c# code behind*/
 
[WebMethod]
public static UserDetails[] BindDatatable()
{
DataTable dt = new DataTable();
List<UserDetails> details = new List<UserDetails>();
using (SqlConnection connnection = new SqlConnection(ConfigurationManager.ConnectionStrings["dbconnection"].ConnectionString.ToString()))
{
using (SqlCommand cmd = new SqlCommand("SELECT Fabrics.ImageName,Fabrics.Descript,ImageAssignedName from Fabrics", connnection))
{
connnection.Open();
SqlDataAdapter da = new SqlDataAdapter(cmd);
da.Fill(dt);
foreach (DataRow dtrow in dt.Rows)
{
UserDetails user = new UserDetails();
user.ImageName = dtrow["ImageName"].ToString();
user.Descript = dtrow["Descript"].ToString();
user.ImageAssignedName = dtrow["ImageAssignedName"].ToString();
details.Add(user);
}
}
}
return details.ToArray();
}
public class UserDetails
{
public string ImageName { get; set; }
public string Descript { get; set; }
public string ImageAssignedName { get; set; }
}
 
 
 

Answers (4)

0
Photo of Rafnas T P
NA 12.2k 435.7k 7y
you can create two setup files one for trial varsion with online server connection details, another one is with sql local connection string
Accepted
1
Photo of Kashif Asif
NA 462 54.8k 7y
for online you have to purchase a online mssql database and change connection string according to the credantial and when demo complete delete that database or make a function in your application that close automatically after some Duration. and for offline just install mssql database on client mechine and and change the connection string.
0
Photo of Jyoti Jodha
NA 1.7k 40.7k 7y
if create two setup files then Client need to two files download.....???
0
Photo of Jyoti Jodha
NA 1.7k 40.7k 7y
Hello

Rafnas T P

 yes i am want Client install Demo 
then work online Sql Server
 
or Client purchase and install Sql server and database file available then work offline database
0
Photo of Rafnas T P
NA 12.2k 435.7k 7y
if you have already have online database then just give that database connection string into your winform app, then ship that to your client
0
Photo of Rafnas T P
NA 12.2k 435.7k 7y
hi jyothi,
what do you mean by online and offline in winform application,
it is always an offline app,
if you want you can make database online server
0
Photo of Jyoti Jodha
NA 1.7k 40.7k 7y

Already purchase  online SQL Server database