繁体   English   中英

GridView ASP.Net中的ViewState

[英]ViewState in GridView ASP.Net

我有一个网格视图连接到aspx代码中的数据源。 选定的gridview行在按钮上的clcik中隐藏。 我想永久隐藏该行,即使用户注销并且隐藏的行中的日志也不应显示。 我曾尝试使用ViewState,但它不起作用。 任何人都对如何实现这一目标有任何想法。

我的GridView:

edit Select Approve data 1 data 2 data 3

当用户单击“选择”并且“批准”按钮时,该行被隐藏。 我希望所有行都被调用,除了被单击的行之外,被单击的行根本不应该显示。 我做了一些研究,发现ViewState是最好的,但不知道如何实现。

我的后台代码:

SqlConnection con = new SqlConnection("Data Source=User-PC\\User;Initial Catalog=Subject Registration System;Integrated Security=True");

    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["username"] != null)
        {
            Label1.Text = Session["username"].ToString();

        }

        con.Open();


        SqlCommand cmd = new SqlCommand("SELECT FullName FROM [Programme Leader] WHERE Username= '" + Label1.Text + "'", con);
        SqlDataReader reader = cmd.ExecuteReader();

        reader.Read();
        Label1.Text = reader["FullName"].ToString();
        reader.Close();

        con.Close();



        if (!Page.IsPostBack)
        {
            string gd;
            gd = (string)ViewState["Gridview"];
        }



        Panel2.Visible=true;
        Panel3.Visible = false;
    }

    protected void DDL1_SelectedIndexChanged(object sender, EventArgs e)
    {

        Panel2.Visible = true;

    }



    protected void GridView2_RowEditing(object sender, GridViewEditEventArgs e)
    {

        Panel2.Visible = true;
        GridView2.DataBind();
    }

    protected void GridView2_RowUpdated(object sender, GridViewUpdatedEventArgs e)
    {

        Panel2.Visible = true;
        GridView2.DataBind();

    }



    protected void Button1_Click(object sender, EventArgs e)
    {

          GridView1.SelectedRow.Visible = false;

        ViewState["gridview"]=GridView1;



    }


    protected void Button2_Click(object sender, EventArgs e)
    {
    Response.Redirect("~/Programme Leader Front Page.aspx");
    }



 }



}

谢谢

如果隐藏的行与特定用户相关联,则可以将该行保留到数据库中。 因此,新表将包含来自gridview的行的主键以及用户ID。 对gridview执行选择时,只需排除存储在新表中的用户行。

视图状态是ASP.NET页面框架在往返之间保留页面和控件值的方法。 在您的情况下,视图状态将不起作用,因为您希望用户注销后信息仍然存在。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM