c# - 如何从代码隐藏的转发器控件中获取整行?

标签 c# asp.net .net repeater

我正在使用转发器控件来创建一个只有几行和几列的表格。在 Repeater_ItemCommand 上,我想在后面的代码中选择单击的行并将其存储在 session 中。我该怎么做?

当我单击该行时,我的 e.Item.DataItem 变为 NULL。我正在使用 <%# DataBinder.Eval(Container.DataItem, "FILE_NAME")%> 在 asp.net 中绑定(bind)我的值

我不会使用 LINQ。

谢谢 已

最佳答案

这是转发器的代码

<asp:Repeater ID="Repeater1" runat="server" 
        onitemcommand="Repeater1_ItemCommand">
        <HeaderTemplate>
            <ul>
        </HeaderTemplate>
        <ItemTemplate>
        <li>
            <asp:LinkButton ID="btnDeleteComment" runat="server" Text="Delete" CommandName="DeleteComment" CommandArgument=<%#Eval("myId") %>></asp:LinkButton>
            <asp:Label ID="Label1" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "FileName")%>'></asp:Label>
            </li>
        </ItemTemplate>
        <FooterTemplate>
        </ul>
        </FooterTemplate>
    </asp:Repeater>

下面是后面的代码

public partial class _Default : System.Web.UI.Page
    {
        public class myObject
        {
            public string FileName { get; set; }
            public int myId { get; set; }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            List<myObject> myList = new List<myObject>();
            myList.Add(new myObject {myId = 1, FileName = "one" });
            myList.Add(new myObject { myId = 2, FileName = "two" });
            myList.Add(new myObject { myId = 3, FileName = "three" });

            Repeater1.DataSource = myList;
            Repeater1.DataBind();
        }

        protected void Repeater1_ItemCommand(object source, RepeaterCommandEventArgs e)
        {
            Label item = (Label)e.Item.FindControl("label1");

        }
    }

关于c# - 如何从代码隐藏的转发器控件中获取整行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12307529/

相关文章:

asp.net - ASP.NET网站的XSS攻击

javascript - 无法访问对象的 JSON 数组,让我抓狂

ASP.NET Mvc 5 返回带有 seo 友好 url 的 View

c# - 使用 AsCacheQueryable 和通用查询性能高效地从 Ignite 获取数据

c# - "[Authorize(Roles = ADMIN)]"中的括号在 ASP.NET 中意味着什么?

c# - 如何强制 winforms 应用程序使用我在每台机器上指定的字体/字体大小?

c# - XNA Visual Studios 2010 异常部署错误

c# - 如何获取原型(prototype)文件来引用另一个原型(prototype)中定义的消息?

c# - 如何使用结构图获取泛型类的所有实例

c# - 将 GetComponent<>() 与变量一起使用?