John
John

Reputation: 1

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 = 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

Upvotes: 0

Views: 6812

Answers (1)

Jammin
Jammin

Reputation: 3090

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;

        }
    }

Upvotes: 2

Related Questions