Default2.aspx :

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>无标题页</title>
        <script language="ecmascript" type="text/javascript">
function DisAppear(id)
{
    document.getElementById("DelAttach").value=id;
    document.forms[0].submit();
}
function ItemId(id)
{
    document.getElementById("ItemID").value=id;
    document.forms[0].submit();
}
</script>
</head>
<body>
    <form >
                            面板四
                        </td>
                    </tr>
                </table>
            </asp:View> 
        </asp:MultiView>
    </form>
</body>
</html>

Default2.aspx.cs :

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class Default2 : System.Web.UI.Page
{
    private static string sItems = "";//2◆3◆4
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
            sItems = "";
        DelLinkItems();
        SetLinkItems();
    }
    protected void DelLinkItems()
    {
        string strID = DelAttach.Value.Trim();
        if (strID != "")
        {
            sItems = LeaveItems(sItems, strID);
            LinkItems.InnerHtml = "";
            LinkItems.InnerHtml = GetHtmlItems(sItems);
        }
        DelAttach.Value = "";
    }

    protected string LeaveItems(string sItems, string sItem)
    {
        string[] sTemp;
        string nItems = "";
        sTemp = sItems.Split('◆');

        for (int i = 0; i < sTemp.Length; i++)
        {
            if (sTemp[i].ToString() != sItem)
            {
                nItems += (nItems != "") ? "◆" + sTemp[i].ToString() : sTemp[i].ToString();
            }
        }
        return nItems;
    }

    protected void SetLinkItems()
    {
        string strID = ItemID.Value.Trim();
        if (strID != "")
        {
            MultiView1.ActiveViewIndex = Int32.Parse(ItemID.Value.ToString());
        }
        ItemID.Value = "";
    }

    protected string GetCommHtml()
    {
        string sHtml = "<input id=\"ItemButton1\" type=\"button\" ";
        sHtml += "value=\"面板一\" runat=\"server\" style=\"cursor:hand;\" ";
        sHtml += "onclick=\"javascript:ItemId('0')\" />";
        return sHtml;
    }
    protected string GetSpecialHtml(string i, string sText)
    {
        string sI = Convert.ToString(Convert.ToUInt16(i) - 1);
        string sHtml="&nbsp;&nbsp;";
        sHtml += "<input type=\"button\" runat=\"server\" value=\"" + sText + "\" ";
        sHtml += "ID=\"ItemButton" + i + "\"  OnClick=\"javascript:ItemId('"+sI+"')\" ";
        sHtml += "style=\"cursor:hand;\" ";
        sHtml += "/>";
        sHtml += "<a href=\"javascript:DisAppear('" + i + "')\">";
        sHtml += "<img src='Del.jpg' alt=\"关闭\" border=0>";
        sHtml += "</a>";
        return sHtml;
    }
    protected bool IsShowItems(string sItems,string sItem)
    {
        if (sItems != "")
        {
            string[] sTemp;
            sTemp = sItems.Split('◆');

            for (int i = 0; i < sTemp.Length; i++)
            {
                if (sTemp[i].ToString() == sItem)
                {
                    return true;
                }
            }
        }
        return false;      
    }
    protected string GetHtmlItems(string sItems)
    {
        string[] sTemp;
        string sHtml = GetCommHtml();
       
        sTemp = sItems.Split('◆');

        for (int i = 0; i < sTemp.Length; i++)
        {
            switch(sTemp[i].ToString()) 
            {
                case "1":
                    break;
                case "2":
                    sHtml += GetSpecialHtml("2", "面板二");
                    break;
                case "3":
                    sHtml += GetSpecialHtml("3", "面板三");
                    break;
                case "4":
                    sHtml += GetSpecialHtml("4", "面板四");
                    break;
                default:
                    break;
            }    
        }
        sHtml += "<br /><br />";
        return sHtml;
    }
    protected void Button2_Click(object sender, EventArgs e)
    {
        //sItems += "◆2";
        if (!IsShowItems(sItems,"2"))
            sItems += (sItems != "") ? "◆2" : "2";

        LinkItems.InnerHtml = "";
        LinkItems.InnerHtml = GetHtmlItems(sItems);

    }
    protected void Button3_Click(object sender, EventArgs e)
    {
        //sItems += "◆3";
        if (!IsShowItems(sItems, "3"))
            sItems += (sItems != "") ? "◆3" : "3";

        LinkItems.InnerHtml = "";
        LinkItems.InnerHtml = GetHtmlItems(sItems);
    }
    protected void Button4_Click(object sender, EventArgs e)
    {
        if (!IsShowItems(sItems, "4"))
            sItems += (sItems != "") ? "◆4" : "4";

        LinkItems.InnerHtml = "";
        LinkItems.InnerHtml = GetHtmlItems(sItems);
    }
}

相关文章: