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!

DropDownList prob 1

Status
Not open for further replies.

Stretchy

Programmer
Mar 26, 2002
87
GB
Hi.. I have a dropdownlist controlling one of my web pages. The problem is the first item (top item) which doesnt work...Am i right in asuming that this is .NET being too clever and disabling the top item in case it will be used for someone to right "click here" or "select" into?

If this is the case (even if it isnt) how can I get the top item to work?

Thx for any help

_______________
Stretchy [Pipe]
 
What do you mean by "doesn't work"? Is it not showing up, or not doing anything when selected, etc.?

One thing to keep in mind is that the drop down list (and pretty much almost everything else in vb.net) uses a 0-based index.

So item 1 is really item 0. Maybe you're missing that 0 indexed item?

Jack
 
Thats what i was thinking. What I mean by not working is that it is the only item that does nothing when i click on it (it should open a new page)

Thx for your help _______________
Stretchy [Pipe]
 
Maybe post your code then, and we'll have a look.

Jack
 
Ok.. this is the Tag on the aspx

&quot;<asp:dropdownlist id=DropDownList1 runat=&quot;server&quot; Font-Names=&quot;Tahoma&quot; DataValueField=&quot;Category&quot; DataTextField=&quot;Category&quot; DataSource=&quot;<%# DataSet11 %>&quot; Height=&quot;15px&quot; BackColor=&quot;#C4CEFF&quot; AutoPostBack=&quot;True&quot; Width=&quot;159px&quot;>
</asp:dropdownlist>&quot;

Apart from that there is the code behind..

&quot;
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

If IsPostBack Then
Me.OleDbDataAdapter1.SelectCommand.CommandText += &quot; WHERE [Story Category]= '&quot; & Me.DropDownList1.SelectedItem.Value & &quot;' &quot;
Me.legweek.Text = &quot;Chosen Category : &quot; & Me.DropDownList1.SelectedItem.Value
Me.legcount.Text = &quot;Category Total&quot;

Else
Me.OleDbDataAdapter1.SelectCommand.CommandText += &quot; WHERE [Date Created]>= #&quot; & Date.Today.AddDays(-7).ToString(&quot;MM/dd/yyyy&quot;) & &quot;# And [Date Created]<=#&quot; & Date.Today.ToString(&quot;MM/dd/yyyy&quot;) & &quot;# ORDER BY Tbl_Press.[Date Created];&quot;
Me.legweek.Text = &quot;Latest News&quot;
Me.legcount.Text = &quot;Total News Items This Week&quot;

End If
Me.OleDbDataAdapter1.Fill(DataSet51)
Me.OleDbDataAdapter2.Fill(DataSet11)
Me.OleDbDataAdapter3.Fill(DataSet21)
Me.repeater1.DataSource = DataSet51.Tables(&quot;webQuery&quot;).DefaultView

DataBind()

If IsPostBack Then
Me.legcount2.Text = Me.DataSet51.webQuery.Rows.Count
Else
Me.legcount2.Text = Me.DataSet51.webQuery.Rows.Count

End If

End Sub

End Class
&quot;

All of the other items work fine in the dropdownlist. This is the only problem i have with the page.

Thx again _______________
Stretchy [Pipe]
 
I think I may have it. When the list is loaded the first item comes up as selected right? Now a drop down event handler is based on the change selected index event I believe. Logically it is impossible to change the selected index to the first item as it is already there. When you select another item in the list the page is posted back your code runs but then the drop down selected index is reset to index 0. (Still with me? Cause I am losing myself). Anyway, one way to get around this is to add a title to the drop down so that the first item is not functional.

dropdown.Items.Insert(0, &quot;Title&quot;)
dropdown.Items(0).Value = &quot;Value&quot;


The other way to do this is to make sure that the drop down selected index stays on the previously selected item. That way the event will still fire when item index 0 is selected

Hope that does it for you [peace]
 
Thats wot i was thinkin again [thumbsup2] by adding a title i could knock the first item down.

Thx v.much Zarcom _______________
Stretchy [Pipe]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top