Is it possible to grab the cell data from Repeater items property such as
Dim test As String = myRepeater.Items(index).DataItem(2)
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 l开发者_如何学Pythonight on this.
Not directly -- remember, repeaters are very, very simple webcontrols and the repeater itself really has a limited idea of what is underneath it.
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: it has been a long time since I laid down significant web forms code, no garuntees I got the class names, etc, exactly right.
精彩评论