2013-05-06 127 views
0

我有一个下拉菜单,获取产品信息并通过存储过程进行填充。我试图让所选产品显示在标签中,因此当用户选择一种产品并转到另一种产品时,它会在填充GridView时显示每个项目。一切工作正常,除了我的标签!它目前显示“请选择产品”,但从不改变。标签中显示的选定项目

If DS.Tables.Count > 0 AndAlso DS.Tables(0).Rows.Count > 0 Then 
    ProdNames.DataSource = DS ' ProdNames is the dropdown 
    ProdNames.DataBind() 
    ProdNames.Items.Insert(0, New ListItem("--Please Select A Product--", "0")) 

    desc = ProdNames.SelectedItem.Text 
    Product.Text = "Product: " & desc & "" 'Product is my label name. 
End If 

任何帮助将不胜感激。

+0

这是在Web应用程序或桌面应用程序? – misleadingTitle 2013-05-06 14:19:15

+0

嗨它的一个网络应用程序 – user2354956 2013-05-06 14:25:54

回答

1

你似乎试图设置此列表时绑定。当下拉菜单的选定索引更改时,您需要更改标签文本。

ASPX

<asp:DropDownList ID="ProdNames" runat="server" AutoPostBack="true" /> 
<asp:Label ID="Product" runat="server" /> 

代码隐藏

Private Sub ProdNames_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ProdNames.SelectedIndexChanged 

If ProdNames.SelectedItem IsNot Nothing Then 

Product.Text = ProdNames.SelectedItem.Text 

End If 
End Sub 
+0

谢谢,看了你的建议后,我发现当我移动它一切都很好。哦,这些简单的驱使我疯了!再次感谢! – user2354956 2013-05-06 15:19:39