几个常用控件的练习总结(radioButtonList,MultiView,Adratator,Literal,Panel控件中动态添加文本框)

来源:互联网 发布:怎么刷网络课程 编辑:程序博客网 时间:2024/06/06 00:44

1.radioButtonList常用属性:SelectedItem.Text;Selected.Text;
2.MultiView的常用属性:ActiveViewIndex;
3.Adratator控件主要是写XML文件
例,如下 :


4. Response.Write(Server.HtmlEncode ("<html>"));//对其进行编码,让它能在页面输出
5.Literal控件的常用属性:LiteralMode
        Literal1.Text = "This is <b>text</b> inserted dynamically";
 
        Literal1.Mode = LiteralMode.Encode;//对其进行编码,让它能在页面输出
 
        Literal1.Mode = LiteralMode.PassThrough;//让它执行标签的作用
6.向Panel控件中动态添加文本框:

 

 

页面代码:
    <div>
        <asp:Panel ID="Panel1" runat="server" BackColor="LightGoldenrodYellow" GroupingText="Panel控件"
            Height="50px" Width="300px">
            作为动态生成的文本框的容器.......</asp:Panel>
   
    </div>
        生成TextBoxes:<asp:DropDownList ID="DropDownList1" runat="server">
            <asp:ListItem>1</asp:ListItem>
            <asp:ListItem>2</asp:ListItem>
            <asp:ListItem>3</asp:ListItem>
        </asp:DropDownList>
后台代码:
        int num = int.Parse(DropDownList1.SelectedItem .Value);
        for (int i = 0; i < num; i++)
        {
            //在页面输出<p>标签
            Panel1.Controls.Add(new LiteralControl("<p>"));
            TextBox t = new TextBox();
            t.Text = "TextBox" + i.ToString();
            t.ID = "TextBox" + i.ToString();
            Panel1.Controls.Add(t);//将生成的文本框添加到panel控件中
        }

原创粉丝点击