Azm Amn

Azm Amn

  • NA
  • 108
  • 17.8k

ViewState in GridView ASP.Net

Feb 24 2017 9:23 PM

I have a gridview that is connected to a datasource in the aspx code. The selected gridview row is hidden on clcik on button. I want to hide the row permenantly, even if user logs off and logs in the hidden row should not be shown. I have tried using ViewState but it doesnt work. Anyone have any idea on how to accomplish this.

My gridview:

edit Select Approve data1 data2 data3

when the user clicks select and the approve button the row is hidden. I want all rows to be called except the one that is clicked, the clicked row should not be displayed at all. I did some research and found out the ViewState is the best but do not know how to accomplish it.

My Behind Code:

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");
}
}
}
 

Thank you


Answers (1)