Dropdown list issues

F

Fendi Baba

I faced 2 isseues. First, I created three (3) dropdown list on my
page. They are populated by an event triggered in the page load
command.

What's strange is that the frist drop downlist gets populated as
expected but the second and third do not get populated at all. I dont
think I made any mistake but can anyone verfiy if I made an error
somewhere?

here is my onload code:

Imports System.Data.SqlClient
Imports System.Web.Configuration
Partial Class supervisor_keyword
Inherits System.Web.UI.Page
Dim strconnectionString As String =
WebConfigurationManager.ConnectionStrings("LocalSqlServer").ConnectionString
Dim con As New SqlConnection(strconnectionString)
Dim cmd As New SqlCommand("", con)
Dim recordcount As String
Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Load
Dim myda As SqlDataAdapter
Dim ds As Data.DataSet
myda = New SqlDataAdapter("SELECT * from gown_AdminStocks",
strconnectionString)
ds = New Data.DataSet
myda.Fill(ds, "AllTables")
GridViewStocks.DataSource = ds
GridViewStocks.DataSource = ds.Tables(0)

GridViewStocks.DataBind()
DropDownListSize.DataSource = ds
DropDownListSize.DataSource = ds.Tables(0)

DropDownListSize.DataTextField =
ds.Tables(0).Columns("SizeID").ColumnName.ToString()
DropDownListSize.DataValueField =
ds.Tables(0).Columns("SizeID").ColumnName.ToString()
DropDownListSize.DataBind()

Dim mydaprice As SqlDataAdapter
Dim dsprice As Data.DataSet
mydaprice = New SqlDataAdapter("SELECT * from
gown_AdminCost", strconnectionString)
dsprice = New Data.DataSet
mydaprice.Fill(dsprice, "CostTables")
GridViewPriceGrid.DataSource = dsprice
GridViewPriceGrid.DataSource = dsprice.Tables(0)
GridViewPriceGrid.DataBind()


DropDownPriceGrid.DataTextField =
dsprice.Tables(0).Columns("CostType").ColumnName.ToString()
DropDownPriceGrid.DataValueField =
dsprice.Tables(0).Columns("CostID").ColumnName.ToString()
DropDownPriceGrid.DataBind()


Dim mydakey As SqlDataAdapter
Dim dskey As Data.DataSet
mydakey = New SqlDataAdapter("SELECT * from
gown_AdminKeyword", strconnectionString)
dskey = New Data.DataSet
mydakey.Fill(dskey, "KeywordTables")
GridViewKeywords.DataSource = dskey
GridViewKeywords.DataSource = dskey.Tables("KeywordTables")
GridViewKeywords.DataBind()


DropDownListKeyword.DataTextField =
dskey.Tables(0).Columns("Keyword").ColumnName.ToString()
DropDownListKeyword.DataValueField =
dskey.Tables(0).Columns("KeywordID").ColumnName.ToString()
DropDownListKeyword.DataBind()



End Sub
End Class

Secondly, when I select the items in the first dropdownlist, It only
returns the value of the first item, irregardless of what has been
selected. This is strnage as I have done this something similar but
never run into this issues. Any thought?

Thanks in advance.
 
F

Fendi Baba

1.You don't seem to set datasource for the second and third ddl.

2.You always reload the first ddl on every postback. Databind it only if
IsPostBack is false.

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]http://msmvps.com/blogs/egoldinhttp://usableasp.net




I faced 2 isseues. First, I created three (3) dropdown list on my
page. They are populated by an event triggered in the page load
command.
What's strange is that the frist drop downlist gets populated as
expected but the second and third do not get populated at all. I dont
think I made any mistake but can anyone verfiy if I made an error
somewhere?
here is my onload code:
Imports System.Data.SqlClient
Imports System.Web.Configuration
Partial Class supervisor_keyword
Inherits System.Web.UI.Page
Dim strconnectionString As String =
WebConfigurationManager.ConnectionStrings("LocalSqlServer").ConnectionStrin­g
Dim con As New SqlConnection(strconnectionString)
Dim cmd As New SqlCommand("", con)
Dim recordcount As String
Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Load
Dim myda As SqlDataAdapter
Dim ds As Data.DataSet
myda = New SqlDataAdapter("SELECT * from gown_AdminStocks",
strconnectionString)
ds = New Data.DataSet
myda.Fill(ds, "AllTables")
GridViewStocks.DataSource = ds
GridViewStocks.DataSource = ds.Tables(0)
GridViewStocks.DataBind()
DropDownListSize.DataSource = ds
DropDownListSize.DataSource = ds.Tables(0)
DropDownListSize.DataTextField =
ds.Tables(0).Columns("SizeID").ColumnName.ToString()
DropDownListSize.DataValueField =
ds.Tables(0).Columns("SizeID").ColumnName.ToString()
DropDownListSize.DataBind()
Dim mydaprice As SqlDataAdapter
Dim dsprice As Data.DataSet
mydaprice = New SqlDataAdapter("SELECT * from
gown_AdminCost", strconnectionString)
dsprice = New Data.DataSet
mydaprice.Fill(dsprice, "CostTables")
GridViewPriceGrid.DataSource = dsprice
GridViewPriceGrid.DataSource = dsprice.Tables(0)
GridViewPriceGrid.DataBind()
DropDownPriceGrid.DataTextField =
dsprice.Tables(0).Columns("CostType").ColumnName.ToString()
DropDownPriceGrid.DataValueField =
dsprice.Tables(0).Columns("CostID").ColumnName.ToString()
DropDownPriceGrid.DataBind()
Dim mydakey As SqlDataAdapter
Dim dskey As Data.DataSet
mydakey = New SqlDataAdapter("SELECT * from
gown_AdminKeyword", strconnectionString)
dskey = New Data.DataSet
mydakey.Fill(dskey, "KeywordTables")
GridViewKeywords.DataSource = dskey
GridViewKeywords.DataSource = dskey.Tables("KeywordTables")
GridViewKeywords.DataBind()
DropDownListKeyword.DataTextField =
dskey.Tables(0).Columns("Keyword").ColumnName.ToString()
DropDownListKeyword.DataValueField =
dskey.Tables(0).Columns("KeywordID").ColumnName.ToString()
DropDownListKeyword.DataBind()
End Sub
End Class
Secondly, when I select the items in the first dropdownlist, It only
returns the value of the first item, irregardless of what has been
selected. This is strnage as I have done this something similar but
never run into this issues. Any thought?
Thanks in advance.- Hide quoted text -

- Show quoted text -
Elliyahu

1. In both the second and third ddl, i set these respectively:

> Dim mydaprice As SqlDataAdapter

DropDownPriceGrid.DataBind()



and


Dim mydakey As SqlDataAdapter

DropDownListKeyword.DataBind()

Is this done wrongly?

Thanks gfor your input. I think the Ispost back issue might be the
cause of the second problem.
 
F

Fendi Baba

Elliyahu

1. In both the second and third ddl, i set these respectively:


DropDownPriceGrid.DataBind()

and

Dim mydakey As SqlDataAdapter

DropDownListKeyword.DataBind()



Is this done wrongly?

Thanks gfor your input. I think the Ispost back issue might be the
cause of the second problem.- Hide quoted text -

- Show quoted text -

Elliyahu

I saw the problem with the datasource. Thanks for pointing it out.

Regards
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top