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 セッション値が再び null になるためです。他の方法を提案してください。
aspx
<asp:ListView ID="theme5" runat="server" DataSourceID="SqlDataSource5">
<ItemTemplate>
<asp:Label ID="lblcountry" runat="server" Text='<%#Eval("Country") %>' />
</ItemTemplate>
</asp:ListView>
ここでは、ラベルのテキスト値を取得してセッションに転送したいと考えています。問題があると思います:
Label country = (Label)theme5.FindControl("lblcountry");
ここの国では、ダブギング中にnull値が見つかりました。