我要自己订制下拉列表中的内容,从表中读取并做处理,请问.net下如何实现?
<td style="width: 135px">
<asp:DropDownList ID="fulei" runat="server"></asp:DropDownList>
<%call show_fulei%> </td>'<%call show_fulei%>只能放在droplist外面,里面不让放sub show_fulei
Dim connstr As String = ConfigurationSettings.AppSettings("ConnectionString")
Dim queryString As String = "select id,mingcheng from lanmu where fulei = 0 order by paixu"
Using connection As New OdbcConnection(connstr)
Dim command As New OdbcCommand(queryString, connection)
connection.Open()
Dim reader As OdbcDataReader = command.ExecuteReader()
While reader.Read()
'response.write(reader.getString(0)&" | "&reader.getString(1) & "<br>")
response.Write("<asp:ListItem Value=""" & reader.getString(0) & """>" & reader.getString(1) & "</asp:ListItem>")
End While
reader.Close()
End Using
end sub
<td style="width: 135px">
<asp:DropDownList ID="fulei" runat="server"></asp:DropDownList>
<%call show_fulei%> </td>'<%call show_fulei%>只能放在droplist外面,里面不让放sub show_fulei
Dim connstr As String = ConfigurationSettings.AppSettings("ConnectionString")
Dim queryString As String = "select id,mingcheng from lanmu where fulei = 0 order by paixu"
Using connection As New OdbcConnection(connstr)
Dim command As New OdbcCommand(queryString, connection)
connection.Open()
Dim reader As OdbcDataReader = command.ExecuteReader()
While reader.Read()
'response.write(reader.getString(0)&" | "&reader.getString(1) & "<br>")
response.Write("<asp:ListItem Value=""" & reader.getString(0) & """>" & reader.getString(1) & "</asp:ListItem>")
End While
reader.Close()
End Using
end sub
解决方案 »
- 优酷上的视频在iphone上播放是flv格式吗?
- 发一个程序员做的壁纸,附psd文件
- 寻求asp.net网站开发武汉地区合作人
- 网上获取真实IP的代码,提示“当前上下文中不存在名称“Text””
- 关于ajax控件AjaxControlToolkit.dll问题?????????????实在没有分了,大家包含
- asp弹出窗口中n个checkbox任意选取,在主页面的text中马上更新并显示
- 无法将类型“double”隐式转换为“System.Random”
- 2003server下,用内网IP地址浏览asp页面时会弹出登陆对话框
- 在页面修改后在另一个页面刷新
- .net组件引用,急急
- 出来诈到。。。问个问题。
- vs2003事件問題
fulei.DataTextField = "你要显示的字段名称";
fulei.DataValueField = "××";fulei的value值
fulei.DataBind();
<asp:ListItem Value="">小学</asp:ListItem>
<asp:ListItem Value="一年级">--一年级</asp:ListItem>
<asp:ListItem Value="二年级">--二年级</asp:ListItem>
<asp:ListItem Value="三年级">--三年级</asp:ListItem>
<asp:ListItem Value="">中学</asp:ListItem>
<asp:ListItem Value="初一">--初一</asp:ListItem>
<asp:ListItem Value="初二">--初二</asp:ListItem>
<asp:ListItem Value="初三">--初三</asp:ListItem>表内容
id mingcheng fu
1 小学 0
2 一年级 1
3 二年级 1
4 三年级 1
5 中学 0
6 初一 5
7 初二 5
8 初三 5
、
web控件,至少在asp下,是很灵活可以自己写<option></option>的
void CreateDropList(ListItem itm)
{
DataView dv = new DataView()
dv.Table = ds.Tables[0];
dv.RowFilter = (itm == null) ? "id=0" : string.Format("fu={0}",itm.Value); foreach(DataRowView drv in dv)
{
ListItem item = new ListItem();
item.Text = drv["mingcheng"].ToString();
item.Value = drv["id"].ToString();
fulei.Items.Add(item);
CreateDropList(item);
}
}第一次调用此方法使用CreateDropList(null);