DropDownList1.DataSource=ds.Tables["types"].DefaultView;
DropDownList1.DataTextFiels="typename";
DropDownList1.DataValueField="id";
DropDownList1.DataBind();
中DropDownList1.DataValueField="id";
其中DataValueField是这个Text对应的值
可以使用
DropDownList1.SelectItem.Value;
DropDownList1.SelectItem.Text;
DropDownList1.DataTextFiels="typename";
DropDownList1.DataValueField="id";
DropDownList1.DataBind();
中DropDownList1.DataValueField="id";
其中DataValueField是这个Text对应的值
可以使用
DropDownList1.SelectItem.Value;
DropDownList1.SelectItem.Text;
解决方案 »
- 如何获取web源码中td的大小?
- datagrid 导出Excel 的分页问题
- 超难的数据绑定和数据库创建.忘高人指点 40分求指点
- 上传到ftp的aspx页面文件为什么会自动改变代码或添加代码
- CutBug 请来领100分,共300分!
- Microsoft.Web.UI.WebControls.dll 为什么 我的树型控件为什么都是文字没有图表也没有 超连接阿?
- 用CHECKBOX或着CHECKBOXLIST实现多选,但是我希望写入数据库的信息是分开来写的
- 如何彈出一個指定大小的IE窗口﹖以及如何屏敝上面的工具欄﹖
- 邮件系统源代码
- 求教,用vs.net2005建立了1个ASP窗口后,却无法把控件拖到窗口上来,可我的书说可以拖
- 大家能否谈谈做为一个项目经理的体会(包括规划、开发、实施、协调、客户、员工等等)!(在线等候,来者有分!)
- 有时候为什么按F5出来的页面是以前的页面?
ddl.items.clear()
Dim Item1 as New ListItem()
Item1.Text="All"
Item1.Value="0"
ddl.items.add(Item1)
Dim ConStr as String="data source=127.0.0.1;initial catalog=GVS;Connect Timeout=500000;user id=sa;password=""
Dim MyCon as SqlConnection=New SqlConnection(ConStr)
Dim MyCom as SqlCommand=New SqlCommand(SQl,MyCon)
MyCon.Open()
Dim Reader As SqlDataReader
Reader=MyCom.ExecuteReader
While Reader.Read()
Dim Item As New ListItem()
IF Not IsDbNull(Reader(Text)) Then
IF Trim(Reader(Text))<>"" Then
Item.Text=Reader(Text)
Else
Item.Text=""
End IF
Else
Item.Text=""
End IF
IF Not IsDbNull(Reader(Value)) Then
IF Trim(Reader(Value))<>"" Then
Item.Value=Reader(Value)
Else
Item.Value=""
End IF
Else
Item.Value=""
End IF
ddl.items.add(item)
End While
Reader.Close()
Reader=Nothing
MyCon.Close()
MyCon=Nothing
End Function
利用这一个公用函数就可以绑定所有的DropDownList了,你知需要给它的四个参数赋值就可以了!
DataValueField 绑定的是值
wuqiwhy(水手&菜鸟) 没有必要