Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

dropdown list issue

Status
Not open for further replies.

newbieAl

Programmer
Sep 10, 2007
21
US
I have a drop down list with gridview. When the page loads the option in the drop down is 'select an item'. However the gridview does not load all records when the page is first loaded and the user has not made a selection yet in the drop down. Here is my code:

<asp:dropdownlist id="DropDownList1" runat="server" autopostback="True" önselectedindexchanged="DropDownList1_SelectedIndexChanged">
Select an item
A
B



Protected Sub DropDownList1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles DropDownList1.SelectedIndexChanged
If DropDownList1.SelectedIndex.Equals(0) Then
tabledata.SelectCommand = ("SELECT * FROM
")

End If
End Sub
 
I don't understand the question. From what I can see all you've done is set a SelectCommand property and haven't bound the Grid. What were you expecting to happen...?


-------------------------------------------------------

Mark,
[URL unfurl="true"]http://aspnetlibrary.com[/url]
[URL unfurl="true"]http://mdssolutions.co.uk[/url] - Delivering professional ASP.NET solutions
[URL unfurl="true"]http://weblogs.asp.net/marksmith[/url]
 
After you change the select command for your data source, I believe you need to call your DataGridView's DataBind() method.

Hope this helps,

Alex

[small]----signature below----[/small]
I'm pushing an elephant up the stairs

My Crummy Web Page
 
I've added that but it didn't make a difference. This is what I had:

Protected Sub DropDownList1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles DropDownList1.SelectedIndexChanged
If DropDownList1.SelectedIndex.Equals(0) Then
tabledata.SelectCommand = ("SELECT * FROM
")
gridview1.DataBind()
End If
End Sub

Just to clarify, I want all data to be shown in the gridview the first time the user loads the page, once the user selects a value from the drop down it filters it properly, but the issue is that now when the page loads it has the default value of 'select an item' in the drop down list and it does not list any records.
 
I have a feeling you are leaving out some code. Where are you assigning the select command if SelectedIndex != 0?

I'm sure there is something you are doing differently (perhaps gridview1's DataSource is unassigned until a selection is made?)

Hope this helps,

Alex

[small]----signature below----[/small]
I'm pushing an elephant up the stairs

My Crummy Web Page
 
It worked once I put the code under page load.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top