获取数据列表中的图像索引 [英] get image index in datalist
本文介绍了获取数据列表中的图像索引的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好
我正在使用数据列表在imagebutton中查看数据库中的图像,我做到了,但是没有问题,但
我想在单击图像时转到另一页并显示该图像的所有细节,但在获取图像索引时遇到问题
我在aspx中使用此代码
hi all
i am using datalist to view image from database in imagebutton i do this and no problem but
i want when clicked in image go to another page and display all ditails of this image i have a problem with getting image index
i use this code in aspx
<asp:DataList ID="DataList1" runat="server" RepeatColumns="3" OnItemCommand="DataList1_ItemCommand" BackColor="White" BorderColor="#CCCCCC" BorderStyle="None" BorderWidth="1px" CellPadding="3" GridLines="Both" Width="719px" >
<ItemTemplate>
<asp:ImageButton ID="ImageButton2" runat="server" ImageUrl='<%#Eval("image")%>' CommandName="selectimage" CommandArgument='<%# Eval("id") %>' Width=100 Height=100 /><br />
并在cs
中
and in cs
if (e.CommandName == "selectimage")
{
int Id = int.Parse(e.CommandArgument.ToString());
}
但将索引为空
并知道问题所在
}
but get the index empty
and do know the problem
推荐答案
将您的Id字段设置为DataKeyField,然后尝试检索其值:
在Datalist的aspx端:-DataKeyField ="id"
由于您需要CommandArgument的唯一值.
Set your Id field as DataKeyField and then try to retrieve its value :
In aspx side of Datalist :- DataKeyField="id"
As you require Unique value for CommandArgument.
设置您的DataList DataKeyField并遵循以下代码:
Set Your DataList DataKeyField and follow the bellow code:
<asp:datalist id="dlPhotos" runat="server" repeatcolumns="5" xmlns:asp="#unknown">
RepeatDirection="Horizontal" BorderColor="#336699" BorderStyle="Solid"
BorderWidth="1px" CellPadding="3" DataKeyField="SLNO"
onitemcommand="dlPhotos_ItemCommand">
<itemtemplate>
<asp:imagebutton id="imgView">
ImageUrl='<%# "Handler.ashx?ImgId=" + Eval("SLNO") %>' runat="server"
Height="110px" Width="150px" CommandName="Select" />
<br />
<asp:label id="Label1" runat="server" text="<%# Eval("PHOTO_TITLE") %>" font-bold="True">
Font-Size="10pt" ForeColor="#336699" Width="100%" />
</itemtemplate>
<itemstyle horizontalalign="Center" verticalalign="Top" />
protected void dlPhotos_ItemCommand(object source, DataListCommandEventArgs e)
{
if (e.CommandName == "Select")
{
int strId = Convert.ToInt32(dlPhotos.DataKeys[e.Item.ItemIndex].ToString());
}
}
这篇关于获取数据列表中的图像索引的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文