asp.net Loop through Datalist and get values of non-control items on button click
Loop through Datalist and get values of non-control items( cell values?) on button click
for (int i开发者_如何学Python = 0; i < datalist1.Items.Count; i++) { datalist1.Items[i]. } Name: '<%#Eval("ElementName")%>' wanna access elementname... by looping through datalist on button click event... button is not on datalist
If i understand your correctly I dont think this is possible, why not just replace it with say a literal, eg
<asp:Literal ID="litFoo" runat="server" Text='<%# Eval("ElementName") %>' />
Then
foreach (DataListItem dli in DataList1.Items)
{
if (dli.ItemType == ListItemType.Item || dli.ItemType == ListItemType.AlternatingItem)
{
Literal foo = dli.FindControl("litFoo") as Literal;
//Or, get the text
string text = ((Literal)dli.FindControl("litFoo")).Text;
}
}
精彩评论