将ID传递给具有Repeater控件的OnClick事件?

编程入门 行业动态 更新时间:2024-10-03 21:18:52
本文介绍了将ID传递给具有Repeater控件的OnClick事件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

这是我的屏幕:

这是我在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事件?

本文发布于:2023-11-03 04:25:03,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1554226.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:控件   事件   ID   Repeater   OnClick

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!