Javascript 单击显示当前图像放大
这是我的密码Javascript 单击显示当前图像放大,javascript,asp.net,css,lightbox,Javascript,Asp.net,Css,Lightbox,这是我的密码 <asp:DataList ID="DataList2" runat="server" BackColor="Gray" BorderColor="#666666" BorderStyle="None" BorderWidth="2px" CellPadding="3" CellSpacing="2" Re
<asp:DataList ID="DataList2" runat="server" BackColor="Gray" BorderColor="#666666"
BorderStyle="None" BorderWidth="2px" CellPadding="3"
CellSpacing="2" RepeatLayout="Flow" Font-Names="Verdana"
Font-Size="Small" GridLines="Both" RepeatColumns="3"
RepeatDirection="Horizontal"
Width="100%">
<FooterStyle BackColor="#F7DFB5" ForeColor="#8C4510" />
<HeaderStyle BackColor="#333333" Font-Bold="True" Font-Size="Large" ForeColor="White"
HorizontalAlign="Center" VerticalAlign="Middle" />
<HeaderTemplate> Employee Details </HeaderTemplate>
<ItemStyle BackColor="White" ForeColor="Black" BorderWidth="2px" />
<ItemTemplate>
<%--imp---*********---------********--%>
<a data-lightbox="roadtrip" href='<%# Eval("Path", "~/PlayerImages/{0}") %>' >
<asp:Image ID="Image1" runat="server" ImageUrl='<%# Bind("Path",
"~/PlayerImages/{0}") %>' Width="50%" Height="50%" />
<%--imp---*********---------********--%>
</a><br />
<b>Employee Name:</b>
<asp:Label ID="lblCName" runat="server" Text='<%# Bind("Name") %>'></asp:Label>
</ItemTemplate>
</asp:DataList>
员工姓名:
我标记为imp的代码区域在第一行中,我设置了
href=''
,因为我想显示当前图像的放大图像,但它不起作用。原因是我认为数据没有绑定到该
href
,因为当我通过一个固定路径代替Eval
时,它会向我显示该图像。我不知道怎么做。
请给我建议解决方案。更改
DataList
定义如下
<asp:DataList ID="DataList2" runat="server" BackColor="Gray" BorderColor="#666666"
BorderStyle="None" BorderWidth="2px" CellPadding="3"
CellSpacing="2" RepeatLayout="Flow" Font-Names="Verdana"
Font-Size="Small" GridLines="Both" RepeatColumns="3"
RepeatDirection="Horizontal"
Width="100%" ItemDataBound="DataList2_ItemDataBound">
<ItemTemplate>
<asp:Literal runat="server" ID="ltrlLightBox"/>
<b>Employee Name:</b>
<asp:Label ID="lblCName" runat="server" Text='<%# Bind("Name") %>'></asp:Label>
</ItemTemplate>
访问ItemDatabound事件中的literal控件
protected void DataList2_ItemDataBound(object sender, DataListItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
Literal ltrlLightBox = (Literal)e.Item.FindControl("ltrlLightBox");
DataRow drow = (DataRow)e.Item.DataItem;
ltrlLightBox.Text = "<a data-lightbox=\"roadtrip\" href=\"PlayerImages/" + drow["Path"].ToString() + "\" > <img src=\"PlayerImages/" + drow["Path"].ToString() + "\" width=\"50%\" height=\"50%\" /></a><br />";
}
}
protectedvoid DataList2\u ItemDataBound(对象发送方,DataListItemEventArgs e)
{
如果(e.Item.ItemType==ListItemType.Item | | e.Item.ItemType==ListItemType.AlternatingItem)
{
Literal ltrlLightBox=(Literal)e.Item.FindControl(“ltrlLightBox”);
DataRow drow=(DataRow)e.Item.DataItem;
ltrlLightBox.Text=“
”;
}
}
您可以使用literal
控件并在ItemDatabound
事件中形成html,然后用此html替换文本。请给出一个示例,说明您绑定到数据列表的数据源是什么?我正在将图像路径和名称绑定到列表耶,这就是我要问的,就像是DataTable或dataview什么的?你的代码可以工作,但我在你的答案中做了一些修改,谢谢