在C#列表视图标签获取标签文本价值 [英] Get Label text-value from Listview label in C#

查看:120
本文介绍了在C#列表视图标签获取标签文本价值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

C#

protected void imgbtn5_Click(object sender, EventArgs e)
{
    Session["theme"] = lbl5.Text;
    foreach (ListViewItem item in theme5.Items)
    {
        Label country = (Label)item.FindControl("lblcountry");
        Session["country"] = country.ToString();        
        Label price = (Label)item.FindControl("lblprice");
        Session["price"] = price.ToString();         
    }       
}

下面,因为的foreach会话值空爬不起来。
请推荐一些其他的方式。

Here because of foreach Session Values get null again. please suggest some other way.

ASPX

<asp:ListView ID="theme5" runat="server" DataSourceID="SqlDataSource5">
<ItemTemplate>
<asp:Label ID="lblcountry" runat="server" Text='<%#Eval("Country") %>' />
</ItemTemplate>
</asp:ListView>

在这里我要得到我的标签文本值,并将其转移到一个会话。
我想有问题:

Here i want to get my label text value and transfer it to a session. I guess there is problem with:

Label country = (Label)theme5.FindControl("lblcountry");

在这里,在我的国家而得到dubugging。找到空值

Here in country i get null value found while dubugging.

推荐答案

您要添加的标签,而不是标签文本

protected void imgbtn5_Click(object sender, EventArgs e)
{
    Session["theme"] = lbl5.Text;
    foreach (ListViewItem item in theme5.Items)
    {
        Label country = (Label)item.FindControl("lblcountry");
// here insted of country.ToString() you Should use 
        Session["country"] = country.Text.ToString();        
        Label price = (Label)item.FindControl("lblprice");
        Session["price"] = price.Text.ToString();         
    }       
}

这篇关于在C#列表视图标签获取标签文本价值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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