我使用C#.NET

我有一个视图(多视图)的每一行包含一个“编辑”按钮内的转发器(存储在CommandArgument在类型ID)。

<asp:Button ID="buttonClick" OnCommand="ButtonClick" CommandArgument='<%#Eval("ID")%>' runat="server" Text="Edit"/>

当上它们通过带到另一个视图(编辑视图)“编辑”按钮,用户点击。

依赖于哪种类型的eval(“ID”)被选择不同的用户控件必须是可见的。

我注意到,如果相同的形式上发生回发(编辑视图)它失去它的状态为动态控制。因此,我认为我需要访问/经由在Page_Load填充DIV(appViewArea)。

在我的Page_Load我只希望它与正确的用户控件填充DIV如果用户访问的编辑视图。以下是我目前有我的Page_Load中。

if(_multiView1.ActiveViewIndex == 1) // This is the Edit View
{
  int typeId = Convert.ToInt32(viewAppointmentID.Value); // viewAppointmentID is a hidden field which is created within the ButtonClick method.

switch (typeId)
{
  case 1:
        {
          var control = Page.LoadControl("~/editBirthAppointment.ascx");
          appViewArea.Controls.Add(control); 
        }
        break;
  case 2:
        {
          var control = Page.LoadControl("~/editDeathAppointment.ascx");
          appViewArea.Controls.Add(control); 
        } 
        break;
}
}

protected void ButtonClick(object sender, CommandEventArgs e)
{
   var viewAppointmentID = Convert.ToInt32(e.CommandArgument);
   _multiView1.ActiveViewIndex = 1;
}

我的问题是,它从来没有进入,如果statament(_mutliview),也并不存储viewAppointmentID。我已经看过了网络上却找不到任何东西,真的帮助了我。上午我访问了错误的方式?

预先感谢任何帮助。

由于

克莱尔

有帮助吗?

解决方案 2

我加入这个代码,而不是到我的按钮事件。它似乎工作现在因此必须ViewState的内将其存储。

其他提示

您不需要你检查命令名和/或commandarguments在Page_Load但是从电网和该事件的按需事件

看来你应该使用

  if(!Page.IsPostback())
       // fill grid here

和在onRowCommand事件时,可以将用户控件添加到页面

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top