文本框中的文本在gridview中消失,来自radiobutton列表,通过Radiobuttonlist1.SelectedIndexChanged

时间:2013-10-05 08:25:26

标签: c# gridview textbox radiobuttonlist

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;
    GridView2.Rows[Convert.ToInt16(value) - 1].Cells[3].Text = items;

 }

这是我写的代码.. 请帮助我。 如有任何疑问,请与我们联系。

1 个答案:

答案 0 :(得分:0)

此文本仅在触发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;


            }
}

希望这有用。