开发者

Dynamic dropdown based on Radio selection

开发者 https://www.devze.com 2022-12-10 05:02 出处:网络
Good morning all! Myself and a co-worker are tasked with a system-wide scripting solution but neither of us are .NET programmers so we need your help.

Good morning all! Myself and a co-worker are tasked with a system-wide scripting solution but neither of us are .NET programmers so we need your help.

We have a GUI that displays a radio selection box (3 options) that are the three sites where our hospitals are. We need to dropdown located on the form to fill with only the locations based on the selected radio option.

my gui http://web6.twitpic.com/img/40330741-85d91a5637f2445b322e62df17cf3351.4aef01c5-full.jpg

Here is the code behind we have so far (sorry, VB)

Public Class frmCEHLI

Private Sub Label1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label1.Click

End Sub

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    'TODO: This line of code loads data into the 'CELocDataSet.dbo_Locations' table. You can move, or remove it, as needed.
    Me.Dbo_LocationsTableAdapter.Fill(Me.CELocDataSet.dbo_Locations)

End Sub

Private Sub btnSubmit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSubmit.Click


    MsgBox("Submit button has been pressed")

End Sub
End Class

For the record the Location dropdown is currently databound but its a static SELECT statement which brings us all the locations but we'd prefer it to be cleaner if it only returned the locations based on Site. We are using Visual Basic 2008 Exp开发者_StackOverflow中文版ress Edition for development. Any help/code is appreciated, thanks!


Sorry not to respond back sooner, busy, and wanted to dig up a sample that did just what you were needing.

Create two comboboxes on your form. You can bind either fixed values, or from a table on the first combo. Then, from the property/events sheet, first set the "AutoPostBack" to TRUE, then on the events, click for the "SelectedIndexChanged" event to bring up some code.

The "Sender" object parameter will be the combobox itself, so you'll be able to analyse the property settings via debugging to find what key/value was chosen.

Then, run whatever query from your data querying control, business object, or whatever that gets your results, such as to a DataSet or DataTable.

Finally, set the datasource of your second combo to the above result query, set dataTextField and DataValueField and issue DataBind() to the combo.

That should get exactly what you need.

Then, when someone makes a selection from the second combo, you can have code within ITS "SelectedIndexChanged" event (also based on its AutoPostBack or actual submit button on the form).

Hope this helps.


I would create two combobox controls... One for the "where", then, on the InteractiveChange event by the user to post-back to the page using that answer for the second combobox of locations based on the "where" value of the first combo.

0

精彩评论

暂无评论...
验证码 换一张
取 消