开发者

asp.net Loop through Datalist and get values of non-control items on button click

开发者 https://www.devze.com 2022-12-26 14:17 出处:网络
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++)

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;

        }
    }
0

精彩评论

暂无评论...
验证码 换一张
取 消