0

我有一个包含许多字段的表单。我想将 4-5 个字段分组,以便它们可以低于自定义标签。如何创建这个?我对编码的了解非常有限。

我想要如图所示的自定义标签:

http://i45.tinypic.com/33agm0y.png

我从网上拿起一个编码并插入它,但它不起作用。

4

1 回答 1

0

首先,创建你的 webusercontrol

WebUserControl1.ascx

这段代码是

<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="WebUserControl1.ascx.cs" Inherits="WebApplication1.WebUserControl1" %>
<asp:Label ID="label" runat="server" >
        </asp:Label>
        <table>
            <tr>
                <td>
                </td>
                <td>
                    <asp:TextBox ID="textbox1" runat="server"></asp:TextBox>
                </td>
            </tr>
            <tr>
                <td>

                </td>
                <td>
                    <asp:TextBox ID="textbox2" runat="server"></asp:TextBox>
                </td>

            </tr>
            <tr>
                <td>
                </td>
                <td>
                    <asp:TextBox ID="textbox3" runat="server"></asp:TextBox>
                </td>

            </tr>
            <tr>
                <td>
                </td>
                <td>
                    <asp:TextBox ID="textbox4" runat="server"></asp:TextBox>
                </td>

            </tr>
            <tr>
                <td>
                </td>
                <td>
                    <asp:TextBox ID="textbox5" runat="server"></asp:TextBox>
                </td>

            </tr>
        </table>

为您的用户控件添加此代码

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace WebApplication1
{
    public partial class WebUserControl1 : System.Web.UI.UserControl
    {
        public string MyProperty { get; set; }

        protected void Page_Load(object sender, EventArgs e)
        {
            label.Text = MyProperty;
        }
    }
}

其次创建你的aspx

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="WebApplication1.WebForm1" %>
<%@ Register TagName="test" TagPrefix="uc" Src="~/WebUserControl1.ascx" %>

<!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>
</head>
<body>
    <form id="form1" runat="server">
    <div>

     <uc:test id="uc1" runat="server" MyProperty="Texte1"></uc:test>
     <uc:test id="uc2" runat="server" MyProperty="Texte2"></uc:test>
     <uc:test id="uc3" runat="server" MyProperty="Texte3"></uc:test>
     <uc:test id="uc4" runat="server" MyProperty="Texte4"></uc:test>


    </div>
    </form>
</body>
</html>
于 2012-06-28T20:10:32.877 回答