此文本只会在 RadioButtonList1_SelectedIndexChanged 事件触发后出现。当您有任何回发时,此文本将消失,因为此事件不会在控件加载事件中引发。确保文本在用户操作期间始终出现。您可以执行以下操作。
private class SelectedItem
{
public string Items { get; set; }
public string Items { get; set; }
}
在 RadioButtonList1_SelectedIndexChanged
protected void RadioButtonList1_SelectedIndexChanged(object sender, EventArgs e)
{
var listControl = (ListControl)sender;
var row = (GridViewRow)listControl.NamingContainer;
var value = listControl.SelectedValue;
var items = listControl.SelectedItem;
var selectedItem =new SelectedItem();
selectedItem.Items = items;
selectedItem.Value= value;
// Save the selected item in the session
Sessions["SelectedItem"] = selectedItem;
}
然后在页面加载事件中,您可以执行以下操作:
protected void Page_Load(object sender, EventArgs e)
{
// check is sessiosn is not null or empty
if(Session["SelectedItem"]!= null)
{
var selectedItem = new SelectedItem();
selectedItem = (SelectedItem)Session["SelectedItem"];
GridView2.Rows[Convert.ToInt16(selectedItem.Value) - 1].Cells[3].Text = selectedItem.Items;
}
}
希望这会有所帮助。