成人午夜激情影院,小视频免费在线观看,国产精品夜夜嗨,欧美日韩精品一区二区在线播放

添加DorpDownList控件的Item子項(xiàng)的三種方法

2010-08-28 10:44:42來源:西部e網(wǎng)作者:

DropDownList控件與ListBox控件最終將會(huì)被解析成為代碼< select >< /select >

DropDownList控件的定義:

<asp:DropDownList id="DropDownList1" runat="server"
DataSource="<% databindingexpression %>"
DataTextField="DataSourceField"
DataValueField="DataSourceField"
AutoPostBack="True|False"
OnSelectedIndexChanged="OnSelectedIndexChangedMethod" />

<asp:Listitem value="value" selected="True|False">
Text
</asp:Listitem>

</asp:DropDownList>

DataSource、DataTextField、DataValueField這三個(gè)屬性的應(yīng)用需要涉及DataBind的知識(shí)AutoPostBack屬性:表示當(dāng)DropDownList控件的所選項(xiàng)發(fā)生改變后,自動(dòng)提交當(dāng)前頁面OnSeletedIndexChanged事件在DropDownList控件所選項(xiàng)發(fā)生變化后發(fā)生。

DropDownList控件的SelectedItem對(duì)象表示在執(zhí)行過程中被選中的Item項(xiàng)、Item項(xiàng)擁有三個(gè)屬性。其一為Text,其二為Value它們分別表示Item項(xiàng)所顯示的文字與所表示的值,如果Value屬性沒有設(shè)置,則默認(rèn)Value屬性值等Text屬性,第三個(gè)屬性Selected則用于判斷某Item項(xiàng)是否被選中添加DorpDownList控件的Item子項(xiàng)。


添加DorpDownList控件的Item子項(xiàng)的方法有三種:


第一種:使用<asp:ListItem>方法

<asp:DropDownList id="weste" runat="server">
          <asp:ListItem Value="0">小學(xué)</asp:ListItem>
          <asp:ListItem Value="1">中學(xué)</asp:ListItem>
          <asp:ListItem Value="2">大學(xué)</asp:ListItem>

</asp:DropDownList>

第二種:使用Items屬性的Add方法1

DropDownList.Items.Add(ItemText)

Items屬性表示DropDownList控件所有Item項(xiàng)的集合,Add操作既是在這個(gè)集合中插入新的Item項(xiàng)。第二種方法用于只設(shè)定Item項(xiàng)的Text屬性(實(shí)際上也指定了Value屬性,此時(shí)Value屬性值等于Text屬性值)。

第三種:使用Items屬性的Add方法2

DropDownListItems.Add(new ListItem)ItemText,ItemValue))

第三種方法同時(shí)設(shè)定了Item項(xiàng)的Text屬性與Value屬性,它是通過添加一個(gè)ListItem類來實(shí)現(xiàn)的。ListItem類使用了兩個(gè)參數(shù),第一個(gè)參數(shù)表示Text屬性值,第二個(gè)參數(shù)表示Value屬性值。

關(guān)鍵詞:DorpDownList
主站蜘蛛池模板: 屯昌县| 荣成市| 白水县| 称多县| 东乡族自治县| 临夏县| 谢通门县| 和静县| 靖西县| 平南县| 桑日县| 关岭| 克拉玛依市| 新和县| 阿合奇县| 库尔勒市| 波密县| 西平县| 黎川县| 福鼎市| 怀来县| 越西县| 平湖市| 台东县| 杭州市| 禹城市| 舒城县| 林周县| 娱乐| 九台市| 桃园市| 万全县| 罗田县| 黄陵县| 宜州市| 准格尔旗| 芮城县| 郸城县| 天峨县| 广灵县| 平顺县|