Ronbear
Ronbear

Reputation: 363

ASP.net problem with changing table row visibility

i have a table array dynamically generated from a data query and stored in a session variable. Now i wanna add a textbox to limit how many rows at a time i will display. To test this, i wrote two button methods, one will set some rows to be visible = false, and the second button method will set the same rows back to visible = true.

protected void limit_btn_Click(object sender, EventArgs e)
{
    for (int i = 0; i < traceTables.Length; i++)
        for (int j = 2; j < traceTables[i].Rows.Count; j++)
            traceTables[i].Rows[j].Visible = false;

    Session["Tables"] = traceTables;
    table_C();
}//end limit_btn_Click()

protected void obo_btn_Click(object sender, EventArgs e)
{
    for (int i = 0; i < traceTables.Length; i++)
        for (int j = 2; j < traceTables[i].Rows.Count; j++)
            traceTables[i].Rows[j].Visible = true;

    Session["Tables"] = traceTables;
    table_C();
}//end obo_btn_Click()

protected void table_C()
{
    String changeTo = log_locations.SelectedValue;
    for (int i = 0; i < sshLoc.Length; i++)
    {
        if (sshLoc[i].CompareTo(changeTo) == 0)
        {
            table_panel.ContentTemplateContainer.Controls.Remove(traceTables[currentTable]);
            System.Diagnostics.Debug.WriteLine("Removing " + sshLoc[currentTable]);
            table_panel.ContentTemplateContainer.Controls.Add(traceTables[i]);
            System.Diagnostics.Debug.WriteLine("Adding " + sshLoc[i]);
            currentTable = i;
            Session["CurrentTable"] = currentTable;
            break;
        }//end if
    }//end for
}//end table_C()

table_C() basically removes and adds the table from the panel - i use it when i want to switch between tables from a dropdown list (which works) and in this case it simply removes and adds the same table from the panel content container.

The problem is that setting the rows to be not visible works fine. Setting the rows back to visible never does, and i'm not sure why

Upvotes: 2

Views: 3005

Answers (2)

Pieter van Kampen
Pieter van Kampen

Reputation: 2077

Try using display:none and display:visible rather than .visible in ASP traceTables[i].Rows[j].Add("style","display:none");

Visible removes it completely from the HTML, so you can only show it again by recreating the page.

Upvotes: 1

Shiraz Bhaiji
Shiraz Bhaiji

Reputation: 65491

You need to store data in a list rather than in a table.

When you set the rows to not visible they are being removed from the html table. That is why you cannot set them to visible again.

If you store the data in a seperate object and bind it to the list, you will be able to turn visibility on and off.

Upvotes: 0

Related Questions