varun sharma

varun sharma

  • NA
  • 150
  • 2.7k

How to make DataList clickable and open with unique id

Feb 11 2018 1:22 AM
<asp:DataList ID="dlCustomers" runat="server" RepeatColumns="4" CellSpacing="0" RepeatLayout="Table">
<ItemTemplate>
<table class="table">
<tr>
<th colspan="2">
<b>
<%# Eval("Name") %></b>
</th>
</tr>
<tr>
<td colspan="2">
<asp:Label ID="lblId" Text='<%# Eval("id") %>' runat="server" />,
<%# Eval("ContentType") %>
</td>
</tr>
<tr>
<td>
Image:
</td>
<td>
<asp:ImageButton ID="imgImage" runat="server" ImageUrl='<%# "data:jpg;base64," + Convert.ToBase64String((byte[])Eval("Data")) %>'
Height="75px" Width="75px"/>
</td>
</tr>
<tr>
<td colspan="2">
Name:
<%# Eval("Name")%>
</td>
</tr>
<tr>
<td colspan="2">
ContentType:
<%# Eval("ContentType")%>
</td>
</tr>
</table>
</ItemTemplate>
</asp:DataList>
 
 
 
 
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
DataTable dt = this.GetData();
dlCustomers.DataSource = dt;
dlCustomers.DataBind();
}
}
 
private DataTable GetData()
{
string conString = ConfigurationManager.ConnectionStrings["conString"].ConnectionString;
using (SqlConnection con = new SqlConnection(conString))
{
using (SqlCommand cmd = new SqlCommand("SELECT id, Name, ContentType,Data from tblFiles "))
{
using (SqlDataAdapter sda = new SqlDataAdapter())
{
cmd.Connection = con;
sda.SelectCommand = cmd;
using (DataTable dt = new DataTable())
{
sda.Fill(dt);
return dt;
}
}
}
}
}
 
 
 
 
 
 
 
 
 
 

Answers (2)