Gridview Rowcommand事件触发但显示隐藏控件,包括Gridview未发生

时间:2011-06-28 15:09:33

标签: c# asp.net rowcommand

以下是我尝试通过两个简单步骤完成的工作:

1)New Row(trNewPost),其中包含表格并在其中进行控制以添加新帖子或更新现有帖子。

Default Visible=false;

2)添加按钮使上面的行可见= true;

3)trMyPosts中包含Gridview并显示所有帖子。

默认值visible = true。

当用户点击编辑gridview的任何一行(RowCommand事件)时,我只想隐藏这个网格(trMyPosts)并显示trNewPost。

这就是全部。事件被解雇,但没有发生任何事情。

1 个答案:

答案 0 :(得分:0)

我认为你有观点问题。

您可以做的一件事是:

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            // do things here
        }
    }

因为无论何时发生任何事情,页面都会回发。通过使用Page_Load封装! Page.IsPostBack,可以防止这些事情一次又一次地发生。

现在,如果您的变量是全局变量,那么您将遇到同样的问题。请考虑使用Session变量。

另外,我只想告诉你这段代码以防万一:

    protected void HideShowClicked(object sender, EventArgs e)
    {
        // toggle the visibility of the control
        // (that is, if visible then hide, if hidden then show) 
        myControl.Visible = ! myControl.Visible;
    }
相关问题