问题描述
这是我的屏幕:
这是我在Repeater中ItemTemplate的代码:
Here is my code for the ItemTemplate in the Repeater:
<ItemTemplate>
<div style="float: left; overflow: hidden; display: inline-block; border-style: solid; margin: 5px; background-color: Silver">
<div style="text-align:center">
<asp:Label ID="lblImage" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "image") %>'></asp:Label>
</div>
<asp:Image runat="server" ID="image1" Width="250px" Height="250px" ImageUrl='<%# DataBinder.Eval(Container.DataItem, "url") %>' />
<div style="text-align: center;">
<asp:Button runat="server" ID="btnNew" Text="New" />
<asp:Button runat="server" ID="btnOriginal" Text="Original" />
</div>
</div>
Repeater在我的程序中使用一个数据集来填充ItemTemplate的标签和图像控件.我的数据集中还有一个名为 graphicID
的字段.我想以某种方式将该字段中的值传递给原始"按钮,以便如果用户按下该按钮,则该特定的 graphicID
会传递到click事件中.这有道理吗?
The Repeater uses a dataset in my program to populate the ItemTemplate's label and image controls. There's another field in my dataset called graphicID
. I'd like to, somehow, pass the value in that field to the 'Original' button, so that if a user presses that button, that particular graphicID
is passed into the click event. Does this make sense?
例如,第二张图片是哈洛克船长.该图像的 graphicID
是 93
.如果用户按下Captain Harlock下的Original按钮,我想将 93
传递给 onClick
事件.不过,我不确定如何执行此操作.如果有人能指出我正确的方向,我将不胜感激!
For instance, the second image is Captain Harlock. The graphicID
for this image is 93
. If the user presses the Original button under Captain Harlock, I want to pass 93
to the onClick
event. I'm not sure how to do this, though. If someone could point me in the right direction, I'd greatly appreciate it!
推荐答案
<div style="text-align: center;">
<asp:Button runat="server" ID="btnNew" Text="New" />
<asp:Button runat="server" CommandName="cmd_original" CommandArgument="name of field which you want to access" ID="btnOriginal" Text="Original" />
</div>
编辑
处于中继器控制下
您必须添加一个如下事件:
you have to add an event as below:
onitemcommand="Repeater1_ItemCommand"
在后面的代码中
protected void Repeater1_ItemCommand(object source, RepeaterCommandEventArgs e)
{
if (e.CommandName == "cmd_original")
{
Int32 id = Convert.ToInt32(e.CommandArgument);
}
}
这篇关于将ID传递给具有Repeater控件的OnClick事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!