I have a problem with dropdownlist that is SOMEWHAT similar with the above issue....
Here's my case.....
---I have a dropdownlist
<asp:dropdownlist id="ddlMediaFormat" runat="server" AutoPostBack="True"></asp:dropdownlist>
---I need to be able to select a mediaformattype in this dropdownlist...to populate my datagrid....this is my page_load
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
If Not Page.IsPostBack Then
PopupateDropdownList()
End If
If ddlMediaFormat.Items.FindByText("MP3").Selected = True Then
PopulateMP3Datagrid()
ElseIf ddlMediaFormat.Items.FindByText("WMA").Selected = True Then
PopulateWMADatagrid()
End If
End Sub
-- And this is my PopupateDropdownList() code
Public Sub PopupateDropdownList()
'**** begin: populate the dropdownlist for media format *****
Dim ddDR As SqlDataReader = Nothing
Dim ddSqlConnection As SqlConnection = New SqlConnection("server=localhost;database=media;user id=uid;password=password;")
Dim ddSqlCommand As SqlCommand = New SqlCommand("SELECT MediaFormatID, MediaFormat FROM tblMediaFormat order by MediaFormatID ", ddSqlConnection)
ddSqlConnection.Open()
ddDR = ddSqlCommand.ExecuteReader(CommandBehavior.CloseConnection)
ddlMediaFormat.DataSource = ddDR
ddlMediaFormat.DataTextField = "MediaFormat"
ddlMediaFormat.DataValueField = "MediaFormatID"
ddlMediaFormat.DataBind()
ddlMediaFormat.Items.Insert(0, "Select")
'**** end: populate the dropdownlist for media format *****
End Sub
-- And my codes for PopulateMP3Datagrid() and PopulateWMADatagrid() is similar except that teh where clause is compared to 'WMA' for PopulateWMADatagrid() while 'MP3' for PopulateMP3Datagrid()
Public Sub PopulateMP3Datagrid()
Dim STR As String
STR = "Select MediaFormat, Media " & _
" from tblMedia " & _
" where MediaFormat = 'MP3'"
Dim cn As SqlConnection = New SqlConnection("server=localhost;database=media;user id=uid;password=password;")
Dim da As SqlDataAdapter = New SqlDataAdapter(STR, cn)
Dim ds As DataSet = New DataSet
da.Fill(ds, "tblMedia ")
dgDownload.DataSource = ds.Tables(0)
dgDownload.DataBind()
End Sub
-- I need to check if the selected text or value is equal to MP3 to invoke PopulateMP3Datagrid() or if it is WMA to invoke PopulateWMADatagrid()...This will determine the items i need to display in the datagrid...
----NOW, my problem is that everytime i run it...i get the value or the text 'SELECT' instead of MP3 or WMA...even if I had already selected either MP3 or WMA....
So what's wrong with my codes? Can anybody help me?
Thank you in advance