'初始化DropDownList While reader.Read() DropList_productid.Items.Add(New ListItem(reader("name"), reader ("ProductID"))) End While为什么不这样写呢? DropList_productid.DataSource=myreader DropList_productid.DataTextField="name" DropList_productid.DataValueField="name" DropList_productid.DataBind();
ameng_2002(wader) : 你的方法我试过了,也是一样的问题。当我把你的DropList_productid.DataValueField="name"这行代码注释掉后, 在DropDownList的SelectedIndexChanged事件中就可以取出当前选项的文本值: planid.Text = DropList_planid.SelectedItem.Text 我把我自己的代码改成如下也没问题了: While reader.Read() DropList_planid.Items.Add(New ListItem(reader("plan_id"))) End While 我不明白的是为什么多加了一个value就不行了呢?但是当我在DropDownList的 SelectedIndexChanged事件中取出当前的value值也没问题,就是有时候取不出正确的 Text值。 实在郁闷,请指点!
我的代码如下,麻烦大家帮忙分析一下: sub page_load(.....) if not ispostback then Dim conn As System.Data.SqlClient.SqlConnection Dim cmd As System.Data.SqlClient.SqlCommand Dim reader As System.Data.SqlClient.SqlDataReader Dim dd = ConfigurationSettings.AppSettings("strConn") conn = New System.Data.SqlClient.SqlConnection(dd) conn.Open() cmd = New System.Data.SqlClient.SqlCommand("select plan_id,productid from plan_stock", conn) reader = cmd.ExecuteReader() While reader.Read() DropList_planid.Items.Add(New ListItem(reader("plan_id"),reader("productid"))) End While end if .......... end subPrivate Sub DropList_planid_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles DropList_planid.SelectedIndexChanged planid.Text = DropList_planid.SelectedItem.Text End Sub
While reader.Read()
DropList_productid.Items.Add(New ListItem(reader("name"), reader ("ProductID")))
End While为什么不这样写呢?
DropList_productid.DataSource=myreader
DropList_productid.DataTextField="name"
DropList_productid.DataValueField="name"
DropList_productid.DataBind();
你的方法我试过了,也是一样的问题。当我把你的DropList_productid.DataValueField="name"这行代码注释掉后,
在DropDownList的SelectedIndexChanged事件中就可以取出当前选项的文本值:
planid.Text = DropList_planid.SelectedItem.Text 我把我自己的代码改成如下也没问题了:
While reader.Read()
DropList_planid.Items.Add(New ListItem(reader("plan_id")))
End While
我不明白的是为什么多加了一个value就不行了呢?但是当我在DropDownList的
SelectedIndexChanged事件中取出当前的value值也没问题,就是有时候取不出正确的
Text值。
实在郁闷,请指点!
sub page_load(.....)
if not ispostback then
Dim conn As System.Data.SqlClient.SqlConnection
Dim cmd As System.Data.SqlClient.SqlCommand
Dim reader As System.Data.SqlClient.SqlDataReader
Dim dd = ConfigurationSettings.AppSettings("strConn")
conn = New System.Data.SqlClient.SqlConnection(dd)
conn.Open()
cmd = New System.Data.SqlClient.SqlCommand("select plan_id,productid from plan_stock", conn)
reader = cmd.ExecuteReader() While reader.Read()
DropList_planid.Items.Add(New ListItem(reader("plan_id"),reader("productid")))
End While
end if
..........
end subPrivate Sub DropList_planid_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles DropList_planid.SelectedIndexChanged
planid.Text = DropList_planid.SelectedItem.Text
End Sub
要不然当改变DropDownList的选项时,就没有任何反映了
例如:如果你的
Page_Load()
{
... //表示有代码
}那么改写成
Page_Load()
{
if (!Page.IsPostBack)
{
... //表示有代码
}
}
While reader.Read()
DropList_planid.Items.Add(New ListItem(reader("plan_id")))
End While
AspNetPager 免费分页控件2.0版发布,新增Url分布功能,欢迎下载使用:http://www.webdiyer.com