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>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<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]