• Welcome to Valhalla Legends Archive.
 

asp:DropdownList

Started by Imperceptus, August 05, 2009, 04:35 PM

Previous topic - Next topic

Imperceptus

I have a drop downlist on a asp.net form that i populate with list items during the load. It looks like
<asp:DropDownList ID="_RiskTolerance" runat="server"
                    Width="150px"></asp:DropDownList>

The CodeBehind I use to add items looks like

    Private Sub FillCombobox(ByVal ComboControl As DropDownList, ByVal dsCombo As DataSet)
        Dim myItem As ListItem
        For Each row As DataRow In dsCombo.Tables(0).Rows
            myItem = New ListItem(row(1), row(0))
            ComboControl.Items.Add(myItem)

        Next
    End Sub


I have tried to figure out what the user is setting the value of a in a dropdownlist.  So far nothing returns what the user chooses.  Item.SelectedItem.value and Item.SelectedIndex both seem like the right choice but the dont return what I thought.

One example

<select name="ctl00$ContentPlaceHolder1$_RiskTolerance" id="ctl00_ContentPlaceHolder1__RiskTolerance" style="width: 150px;">
<option selected="selected" value="1">High Risk</option>
<option value="2">Average Risk</option>
<option value="3">Low Risk</option>
<option value="4">No Risk</option>

</select>

Say I choose Option 4 in my browser and click a button on the page to start the processing of the information on the page.
If I reference _RiskTolerance.SelectedIndex.Value Or _RiskTolerance.SelectedItem.Value, neither of them return a value anywhere close to what I am looking for.

As far as I can figure I have to enable postback for the dropdown for it to fire the "On" events, and preferably I dont want to use postback for this.

Thoughts?
Quote from: Hazard on August 07, 2003, 03:15 PM
Highlight your entire code. Press the delete key. Start over again using Cuphead's CSB tutorial and work your way from their rather than raping code from downloaded sources meant purely for learning purposes. If this does not fix the problem, uninstall Visual Basic and get a new hobby. I suggest Cricket.

MyndFyre

What value are you expecting?
QuoteEvery generation of humans believed it had all the answers it needed, except for a few mysteries they assumed would be solved at any moment. And they all believed their ancestors were simplistic and deluded. What are the odds that you are the first generation of humans who will understand reality?

After 3 years, it's on the horizon.  The new JinxBot, and BN#, the managed Battle.net Client library.

Quote from: chyea on January 16, 2009, 05:05 PM
You've just located global warming.

Imperceptus

#2
well for that drop down box, had i choosen the last value I would rather get a 3 for index or a 4 for selected value.  but instead i get a 0 for index and a 1 for selected value. 

From what I am seeing it doesn't seem to fire any of the "on" events until postback, which sucks.  Any idea's as whether the Ajax drop downs from ajaxtoolkit have the same problem?
Quote from: Hazard on August 07, 2003, 03:15 PM
Highlight your entire code. Press the delete key. Start over again using Cuphead's CSB tutorial and work your way from their rather than raping code from downloaded sources meant purely for learning purposes. If this does not fix the problem, uninstall Visual Basic and get a new hobby. I suggest Cricket.

MyndFyre

Quote from: Imperceptus on August 06, 2009, 07:54 AM
well for that drop down box, had i choosen the last value I would rather get a 3 for index or a 4 for selected value.  but instead i get a 0 for index and a 1 for selected value. 

From what I am seeing it doesn't seem to fire any of the "on" events until postback, which sucks.  Any idea's as whether the Ajax drop downs from ajaxtoolkit have the same problem?
When are you populating your combo box?  For instance:

protected void Page_Load(object sender, EventArgs e)
{
    if (!IsPostBack)
        FillComboBox(_RiskTolerance, myData);
}


You can cause a postback to be raised by setting the drop down list's AutoPostBack property to true.  However, all server-side controls only have their events triggered when a postback is triggered.
QuoteEvery generation of humans believed it had all the answers it needed, except for a few mysteries they assumed would be solved at any moment. And they all believed their ancestors were simplistic and deluded. What are the odds that you are the first generation of humans who will understand reality?

After 3 years, it's on the horizon.  The new JinxBot, and BN#, the managed Battle.net Client library.

Quote from: chyea on January 16, 2009, 05:05 PM
You've just located global warming.

Imperceptus

Postback was something i was trying to avoid, but I think its the only way atm.  Thanks for the info about server-side controls though, thats good to know.
Quote from: Hazard on August 07, 2003, 03:15 PM
Highlight your entire code. Press the delete key. Start over again using Cuphead's CSB tutorial and work your way from their rather than raping code from downloaded sources meant purely for learning purposes. If this does not fix the problem, uninstall Visual Basic and get a new hobby. I suggest Cricket.

MyndFyre

If you're using 3.5 and can reference System.Web.Extensions (alternatively you can use it in 2.0 as long as you have ASP.NET AJAX 1.0 Extensions), you can avoid a complete postback with a couple additions:


<asp:ScriptManager runat="server" EnablePartialRendering="true" ID="smgr" />



<asp:UpdatePanel ID="upd" runat="server">
    <ContentTemplate>
        <asp:DropDownList AutoPostBack="true" .... />
        <%-- Other controls that should be modified by the postback should be placed here --%>
    </ContentTemplate>
</asp:UpdatePanel>


I personally don't like using UpdatePanel but it can help when something needs to be fast.  See "UpdatePanel Considerations" (near the end) of this article - I wrote it (it's ghostwritten, the guy who paid didn't tell me it would be).  Those are my thoughts.  But like I said, it can be helpful.
QuoteEvery generation of humans believed it had all the answers it needed, except for a few mysteries they assumed would be solved at any moment. And they all believed their ancestors were simplistic and deluded. What are the odds that you are the first generation of humans who will understand reality?

After 3 years, it's on the horizon.  The new JinxBot, and BN#, the managed Battle.net Client library.

Quote from: chyea on January 16, 2009, 05:05 PM
You've just located global warming.

Imperceptus

Quote from: Hazard on August 07, 2003, 03:15 PM
Highlight your entire code. Press the delete key. Start over again using Cuphead's CSB tutorial and work your way from their rather than raping code from downloaded sources meant purely for learning purposes. If this does not fix the problem, uninstall Visual Basic and get a new hobby. I suggest Cricket.