090105
应用一:
前台:
- <%@ Page Language="C#" AutoEventWireup="true" CodeFile="selectAttribute.aspx.cs" Inherits="test_selectAttribute" %>
- <!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>
- <style type="text/css">
- input{width:93px;text-align:center;}
- .dis{display:none;}
- .show{display:block;}
- </style>
- </head>
- <body>
- <form id="form1" runat="server">
- <div>
- <div style=" float:left;">
- <div style="text-align: center;">
- <asp:DropDownList ID="ddlN1" runat="server" AutoPostBack="True" OnSelectedIndexChanged="ddlN1_SelectedIndexChanged">
- <asp:ListItem Value="0">设置列名</asp:ListItem>
- <asp:ListItem Value="1">设置属性</asp:ListItem>
- <asp:ListItem Value="2">设置公式</asp:ListItem>
- </asp:DropDownList>
- </div>
- <div style="text-align: center;">
- <asp:Panel ID="pnlN1Name" runat="server" Height="30px" Width="100px">
- <asp:TextBox ID="tbN1Name" runat="server">列名</asp:TextBox>
- </asp:Panel>
- <asp:Panel ID="pnlN1Attribute" runat="server" Height="30px" Visible="false" Width="100px">
- <asp:TextBox ID="tbN1Attribute" runat="server">属性</asp:TextBox>
- </asp:Panel>
- <asp:Panel ID="pnlN1Expression" runat="server" Height="30px" Visible="false" Width="100px">
- <asp:TextBox ID="tbN1Expression" runat="server">公式</asp:TextBox>
- </asp:Panel>
- </div>
- </div>
- <div style="float:left;">
- <div style="text-align:center;">
- <asp:DropDownList ID="ddlN2" runat="server" AutoPostBack="True" OnSelectedIndexChanged="ddlN2_SelectedIndexChanged">
- <asp:ListItem Value="0">设置列名</asp:ListItem>
- <asp:ListItem Value="1">设置属性</asp:ListItem>
- <asp:ListItem Value="2">设置公式</asp:ListItem>
- </asp:DropDownList>
- </div>
- <div style="text-align: center;">
- <asp:Panel ID="pnlN2Name" runat="server" Height="30px" Width="100px">
- <asp:TextBox ID="tbN2Name" runat="server">列名</asp:TextBox>
- </asp:Panel>
- <asp:Panel ID="pnlN2Attribute" runat="server" Height="30px" Visible="false" Width="100px">
- <asp:TextBox ID="tbN2Attribute" runat="server">属性</asp:TextBox>
- </asp:Panel>
- <asp:Panel ID="pnlN2Expression" runat="server" Height="30px" Visible="false" Width="100px">
- <asp:TextBox ID="tbN2Expression" runat="server">公式</asp:TextBox>
- </asp:Panel>
- </div>
- </div>
- </div>
- </form>
- </body>
- </html>
后台:
- 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 test_selectAttribute : System.Web.UI.Page
- {
- protected void Page_Load(object sender, EventArgs e)
- {
- }
- protected void ddlN1_SelectedIndexChanged(object sender, EventArgs e)
- {
- SetVisible("N1", this.ddlN1.SelectedValue);
- }
- protected void ddlN2_SelectedIndexChanged(object sender, EventArgs e)
- {
- SetVisible("N2", this.ddlN2.SelectedValue);
- }
- /// <summary>
- /// 输入列号,和该列下拉框的选择项,决定Panel的显示。
- /// </summary>
- /// <param name="columnsName"></param>
- /// <param name="selectNum"></param>
- private void SetVisible(string columnsName, string selectNum)
- {
- Panel pnlName = (Panel)this.FindControl("pnl" + columnsName + "Name");
- Panel pnlAttribute = (Panel)this.FindControl("pnl" + columnsName + "Attribute");
- Panel pnlExpression = (Panel)this.FindControl("pnl" + columnsName + "Expression");
- switch (selectNum)
- {
- case "0":
- pnlName.Visible = true;
- pnlAttribute.Visible = false;
- pnlExpression.Visible = false;
- break;
- case "1":
- pnlName.Visible = false;
- pnlAttribute.Visible = true;
- pnlExpression.Visible = false;
- break;
- case "2":
- pnlName.Visible = false;
- pnlAttribute.Visible = false;
- pnlExpression.Visible = true;
- break;
- }
- }
- }
end