列表控件(DropDownList,ListBox和BulletedList)

 

列表控件(DropDownList,ListBox和BulletedList).aspx

<% @ Page Language="C#" AutoEventWireup="true" CodeFile="列表控件(DropDownList,ListBox和BulletedList).aspx.cs" Inherits="列表控件_DropDownList_ListBox和BulletedList_"  %>

<! 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 > 列表控件(DropDownList,ListBox和BulletedList) </ title >
</ head >
< body >
    
< form  id ="form1"  runat ="server" >
    
< div >
        
< asp:DropDownList  ID ="DropDownList1"  runat ="server"  OnSelectedIndexChanged ="DropDownList1_SelectedIndexChanged"  AutoPostBack ="True" >
            
< asp:ListItem > 江苏 </ asp:ListItem >
            
< asp:ListItem > 北京 </ asp:ListItem >
            
< asp:ListItem > 上海 </ asp:ListItem >
            
< asp:ListItem > 广州 </ asp:ListItem >
            
< asp:ListItem > 湖南 </ asp:ListItem >
        
</ asp:DropDownList >
        
< br  />
        
< br  />
        
< br  />
        
< asp:ListBox  ID ="ListBox1"  runat ="server"  OnSelectedIndexChanged ="ListBox1_SelectedIndexChanged"  AutoPostBack ="True" >
            
< asp:ListItem > 音乐 </ asp:ListItem >
            
< asp:ListItem > 游戏 </ asp:ListItem >
            
< asp:ListItem > 电影 </ asp:ListItem >
            
< asp:ListItem ></ asp:ListItem >
        
</ asp:ListBox >< br  />
        
< br  />
        
< br  />
        
< asp:BulletedList  ID ="BulletedList1"  runat ="server"
           DisplayMode 
="linkButton"  OnClick ="BulletedList1_Click"   >
            
< asp:ListItem > 数学 </ asp:ListItem >
            
< asp:ListItem > 美术 </ asp:ListItem >
            
< asp:ListItem > 英语 </ asp:ListItem >
            
< asp:ListItem > 计算机 </ asp:ListItem >
        
</ asp:BulletedList >
        
< br  />
        
< br  />
        我现在主要想理解的就是各个空件里面怎样很好的调用各个列表控件里面的每一个属性。Text 或者Value属性倒是没有什么,只要能定位到每一个属性就好,下面我就做一个测试看下
< br  />
        
< asp:TextBox  ID ="TextBox1"  runat ="server"  Style ="position: relative"  Width ="581px" ></ asp:TextBox >< br  />
        根据上面的选择我们在这个里面显示数据
< br  />
        
< br  />
        晕死开始右犯了个错误 郁闷啊,AutoPostBack没有设置点了半天没有反应 呵呵。 BS下自己。
< br  />
        
< br  />
        还有就是这三个空件也都可以进行数据的绑定,和上一个例题里面几乎一样
< br  />
        就试一个看下
< br  />
        
< asp:BulletedList  ID ="BulletedList2"  DisplayMode  ="linkButton"   runat ="server"  DataSourceID ="SqlDataSource1"
            DataTextField
="BLname"  DataValueField ="BLid"  Style ="position: relative"  Width ="250px"  OnClick ="BulletedList2_Click" >
        
</ asp:BulletedList >
        
< asp:SqlDataSource  ID ="SqlDataSource1"  runat ="server"  ConnectionString ="<%$ ConnectionStrings:DBCONNECTIONSTRING %>"
            SelectCommand
="SELECT [BLname], [BLid] FROM [BulletedList]" ></ asp:SqlDataSource >
    
</ div >
    
</ form >
</ body >
</ html >

 

列表控件(DropDownList,ListBox和BulletedList).aspx.cs

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  列表控件_DropDownList_ListBox和BulletedList_ : System.Web.UI.Page
{
    
protected void Page_Load(object sender, EventArgs e)
    
{

    }

    
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
    
{
        
this.TextBox1.Text = this.DropDownList1.SelectedItem.Text;
    }

    
protected void ListBox1_SelectedIndexChanged(object sender, EventArgs e)
    
{
        
this.TextBox1.Text = this.ListBox1.SelectedItem.Text;
    }

    
protected void BulletedList1_Click(object sender, BulletedListEventArgs e)
    
{
        
this.TextBox1.Text = this.BulletedList1.Items[e.Index].Text;
    }

    
protected void BulletedList2_Click(object sender, BulletedListEventArgs e)
    
{
        
this.TextBox1.Text = this.BulletedList2.Items[e.Index].Text;
    }

}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值