图文详解asp.net自带控件
1 Button類控件
三種button控件;
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="單擊按鈕" Height="38px" />
? ? ? ? <asp:ImageButton ID="ImageButton1" runat="server" Height="36px" ImageUrl="~/PT12.jpg"
? ? ? ? ? ? OnClick="ImageButton1_Click" Width="73px" />
? ? ? ? <asp:LinkButton ID="LinkButton1" runat="server" Height="35px" OnClick="LinkButton1_Click"
? ? ? ? ? ? Style="text-align: center" Width="74px" Text="鏈接按鈕"></asp:LinkButton><br />
2 文本類控件
在文本框中輸入內容,輸入完回車,在TextBox1_TextChanged事件中改變Label控件的值;
3 列表框控件
<asp:ListBox ID="lbCity" runat="server" Height="118px" OnSelectedIndexChanged="lbCity_SelectedIndexChanged">
? ? ? ? ? ? <asp:ListItem>10KV</asp:ListItem>
? ? ? ? ? ? <asp:ListItem>35KV</asp:ListItem>
? ? ? ? ? ? <asp:ListItem>110KV</asp:ListItem>
? ? ? ? ? ? <asp:ListItem>220KV</asp:ListItem>
? ? ? ? ? ? <asp:ListItem>330KV</asp:ListItem>
? ? ? ? ? ? <asp:ListItem>500KV</asp:ListItem>
? ? ? ? ? ? <asp:ListItem>1000KV</asp:ListItem>
? ? ? ? </asp:ListBox>
4 單選按鈕
<br />
? ? ? ? <asp:RadioButton ID="rbQH" runat="server" GroupName="xxGroup" Text="小兔子" AutoPostBack="True" OnCheckedChanged="rbMale_CheckedChanged" />
? ? ? ? <asp:RadioButton ID="rbBD" runat="server" GroupName="xxGroup" Text="小狗狗" />
? ? ? ? <asp:RadioButton ID="rbZD" runat="server" GroupName="xxGroup" Text="小白兔" /><br />
5 多選控件
<asp:CheckBox ID="cbYundong" runat="server"
? ? ? ? ? ? OnCheckedChanged="cbYundong_CheckedChanged" Text="小兔子" />
? ? ? ? <asp:CheckBox ID="cbYinyue" runat="server" Text="小狗狗" />
? ? ? ? <asp:CheckBox ID="cbWenxue" runat="server" Text="小貓咪" />
? ? ? ? <asp:CheckBox ID="cbWudao" runat="server" Text="小倉鼠" />
6 多選控件
前后兩個的實現方式不同,代碼如下,一個用CheckBox實現,一個用CheckBoxList實現
<asp:CheckBox ID="cbYundong" runat="server"
? ? ? ? ? ? OnCheckedChanged="cbYundong_CheckedChanged" Text="運動" />
? ? ? ? <asp:CheckBox ID="cbYinyue" runat="server" Text="音樂" />
? ? ? ? <asp:CheckBox ID="cbWenxue" runat="server" Text="文學" />
? ? ? ? <asp:CheckBox ID="cbWudao" runat="server" Text="舞蹈" /><br />
? ? ? ? <br />
? ? ? ? <asp:Label ID="lblMessage" runat="server" Width="266px"></asp:Label><br />
? ? ? ? <br />
? ? ? ? <asp:Button ID="btnSubmit" runat="server" Text="提交" OnClick="btnSubmit_Click" /><br />
? ? ? ? <br />
? ? ? ? <br />
? ? ? ? <br />
? ? ? ? <br />
? ? ? ? 愛好:<asp:CheckBoxList ID="cblHobby" runat="server"
? ? ? ? ? ? RepeatDirection="Horizontal" RepeatLayout="Flow">
? ? ? ? ? ? <asp:ListItem>運動</asp:ListItem>
? ? ? ? ? ? <asp:ListItem>音樂</asp:ListItem>
? ? ? ? ? ? <asp:ListItem>文學</asp:ListItem>
? ? ? ? ? ? <asp:ListItem>舞蹈</asp:ListItem>
? ? ? ? </asp:CheckBoxList><br />
7 日歷控件
前一個SelectMode為Day,后一個為DayWeek;前者只能選定一天,后者可選擇一個星期;
protected void Calendar1_SelectionChanged(object sender, EventArgs e)
? ? {
? ? ? ? Text1.Text = String.Format("You selected {0} date(s).",Calendar1.SelectedDates.Count);
? ? ? ? Text2.Text = String.Format("You selected date:{0}", Calendar1.SelectedDate);
? ? }
工程源碼下載:
http://pan.baidu.com/s/1o6Jtmae
總結
以上是生活随笔為你收集整理的图文详解asp.net自带控件的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: .Net装箱拆箱编程实例
- 下一篇: .net中XML编程总结