ASP.net中继器单个单元格 [英] ASP.net Repeater individual cells

查看:68
本文介绍了ASP.net中继器单个单元格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以从"Repeater items"属性中获取单元格数据,例如

Is it possible to grab the cell data from Repeater items property such as

将测试作为字符串= myRepeater.Items(index).DataItem(2)

Dim test As String = myRepeater.Items(index).DataItem(2)

其中myRepeater具有x行和10列,并已从DataTable绑定

where myRepeater has x rows and 10 columns and was bound from the DataTable

似乎应该是微不足道的,但是看起来无法访问单个单元格.请对此有所了解.

Seems like it should be trivial, but looks like individual cells CAN NOT be accessed. Please shed some light on this.

推荐答案

不是直接的-请记住,转发器是非常非常简单的Web控件,转发器本身对它下面的内容确实有有限的了解.

Not directly -- remember, repeaters are very, very simple webcontrols and the repeater itself really has a limited idea of what is underneath it.

但是您可以轻松获得其中的物品.最好的方法是在项目中使用控件来帮助您查找内容.EG,假设此中继器为行":

But you can easily get at items within. The best method is to use a control within the item to help you find stuff. EG, given this repeater "row":

<ItemTemplate>
  <asp:Button runat="server" ID="theButton" text="Click Me!" OnClick="doIt" /> <asp:TextBox id="theTextBox" value="Whateeavs" />
</ItemTemplate>

您可以使用按钮的点击处理程序在该行中查找其他项目:

You can use the button's click handler to find other items in the row:

protected void doIt(object s, EventArgs e) {
   var c = (Control)s;
   var tbRef = c.NamingContainer.FindControl("theTextBox");
   var tb = (ITextControl)tbRef;
   doSomethingWith(tb.Text);
}

通常比使用绝对定位在行中查找事物更清洁-您不必担心索引等.

Typically much cleaner than finding things in rows using absolute positioning -- you don't have to worry about indexes and such.

PS:自从我编写了重要的Web表单代码以来,已经有很长的时间了,没有让我得到类名的保证金,等等,就完全正确了.

PS: it has been a long time since I laid down significant web forms code, no garuntees I got the class names, etc, exactly right.

这篇关于ASP.net中继器单个单元格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆