簡體   English   中英

在C#中的load事件中保留數據列表數據

[英]Preserve datalist data on load event in c#

我有包含單選按鈕和復選框的數據列表。 如果我選擇其中一些,然后重定向到另一個aspx頁面。 當我轉到上一頁時,必須選中數據列表中的單選按鈕和復選框。 我已經在會話變量中選擇了數據。 如何使用C#執行此操作。

使用ItemDataBound事件,我將檢索單選按鈕並將其值與您的Session變量進行比較

像這樣的東西:

protected void MyDataList_ItemDataBound(object sender, DataListItemEventArgs e)
{
    RadioButton myRadioButton = e.Items.FindControl("myRadioButton") as RadioButton;

    if (myRadioButton == null) { }
    else
    {
        if (string.IsNullOrEmpty(Session[myRadioButton.Value])) {}
        else myRadioButton.Checked = true;        
    }
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM