How to display image inside the datalist?

Posted by Prabu_Spark under ASP.NET on 11/16/2012 | Points: 10 | Views : 9015 | Status : [Member] | Replies : 2
Hi sir,
I design the website to search the employee details, but i cant able to view the image inside the datalist. Kindly give me
the solution for this problem. I attached the design and code below.


Design:
****************************************

<body>
<form id="form1" runat="server">
<div>

<br />
<br />
<asp:Label ID="Label1" runat="server" Text="Dept id"></asp:Label>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>&nbsp;&nbsp;&nbsp;&nbsp;
<asp:Button ID="Button1" runat="server" Text="Search" onclick="Button1_Click" />
<br />
<br />
<asp:DataList ID="DataList1" runat="server"
Caption="Employee Details" CellPadding="4" ForeColor="#333333"
>
<AlternatingItemStyle BackColor="White" />
<FooterStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />
<ItemStyle BackColor="#FFFBD6" ForeColor="#333333" />
<ItemTemplate>
<table border="2" cellpadding="2" width="200px">
<tr>
<td colspan="2" align="center">
<asp:Image ID="image1" runat="server" ImageUrl='<%# DataBinder.Eval(Container.DataItem,"deptid") %>' Height="90px" Width="90px" AlternateText="No Image" BorderColor="ActiveBorder" BorderStyle="Groove" />
</td>
</tr>
<tr>
<td>
<asp:Label ID="Label2" runat="server" Text="Dept ID"></asp:Label>
</td>
<td>
<%# DataBinder.Eval(Container.DataItem,"deptid") %>
</td>
</tr>
<tr>
<td>
<asp:Label ID="Label3" runat="server" Text="Name "></asp:Label>
</td>
<td>
<%# DataBinder.Eval(Container.DataItem,"name") %>
</td>
</tr>
</table>


</ItemTemplate>
<SelectedItemStyle BackColor="#FFCC66" Font-Bold="True" ForeColor="Navy" />
</asp:DataList>
<br />

</div>
</form>
</body>

Code:
**********************

protected void Button1_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(@"Data Source=PRABU-PC;Initial Catalog=spark;Persist Security Info=True;User ID=prabhu;Password=spark123");
SqlCommand cmd;
con.Open();
SqlDataAdapter sda = new SqlDataAdapter();
DataSet ds = new DataSet();
string s = "select * from dept where deptid="+Convert.ToInt32(TextBox1.Text);
cmd = new SqlCommand(s, con);
sda.SelectCommand = cmd;
sda.Fill(ds, "emp");
DataList1.DataSource = ds.Tables["emp"].DefaultView;
DataList1.DataBind();
con.Close();
}

With regards,
J.Prabu.
[Email:prbspark@gmail.com]



Responses

Posted by: Mstnnhan on: 11/16/2012 [Member] Starter | Points: 25

Up
0
Down
well...!!

http://www.centplay.com/affiliate/promotion_7079/ to get more free money:

click here to get free money: http://www.centplay.com/affiliate/promotion_7079/

Prabu_Spark, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Laurenrodriguez on: 11/17/2012 [Member] Starter | Points: 25

Up
0
Down
Hey!
It's resolved ...

Follow this link.

http://www.aspdotnetcodes.com/Insert_Images_Database.aspx[^]


Prabu_Spark, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response