Karen Wilson
asked on
Convert LINQ query from Windows Form to Web UI
I use this type of query a lot in my Windows Forms applications. Is there a comparable for a web application UI? I can see the list being created. I just can't get it to populate in the combobox.
Any help or direction is appreciated!
Karen
Dim getDept = From id In d.tblDepts _
Where id.RespOffice = CStr(Me.PMComboBox.Selecte dItem) _
Group By dpt = id.Dept Into Group _
Order By dpt Ascending _
Select dpt
RemoveHandler Me.cbDept.SelectedIndexCha nged, AddressOf Me.cbDept_SelectedIndexCha nged
Me.cbDept.DataSource = getDept.AsQueryable
Me.cbDept.SelectedIndex = -1
AddHandler Me.cbDept.SelectedIndexCha nged, AddressOf Me.cbDept_SelectedIndexCha nged
Any help or direction is appreciated!
Karen
Dim getDept = From id In d.tblDepts _
Where id.RespOffice = CStr(Me.PMComboBox.Selecte
Group By dpt = id.Dept Into Group _
Order By dpt Ascending _
Select dpt
RemoveHandler Me.cbDept.SelectedIndexCha
Me.cbDept.DataSource = getDept.AsQueryable
Me.cbDept.SelectedIndex = -1
AddHandler Me.cbDept.SelectedIndexCha
ASKER
On page load I have this and I got it working with the databind().
Dim getRspOff = (From id In d.tblDepts _
Group By ro = id.RespOffice Into Group _
Order By ro Ascending _
Select ro).ToList
RemoveHandler Me.PMComboBox.SelectedInde xChanged, AddressOf Me.PMComboBox_SelectedInde xChanged
Me.PMComboBox.DataSource = getRspOff
Me.PMComboBox.DataBind()
Me.PMComboBox.SelectedInde x = -1
AddHandler Me.PMComboBox.SelectedInde xChanged, AddressOf Me.PMComboBox_SelectedInde xChanged
Next I want this code to run when I select an items from the PMCombobox.
Protected Sub PMComboBox_SelectedIndexCh anged(send er As Object, e As EventArgs) Handles PMComboBox.SelectedIndexCh anged
Dim getDept = (From id In d.tblDepts _
Where id.RespOffice = PMComboBox.SelectedItem.Te xt _
Group By dpt = id.Dept Into Group _
Order By dpt Ascending _
Select dpt).ToList
Me.cbDept.DataSource = getDept
Me.cbDept.DataBind()
If cbDept.Items.Count = 1 Then
Dim getSec = From id In d.tblDepts _
Where id.RespOffice = PMComboBox.SelectedItem.Te xt _
And id.Dept = getDept.Item(0) _
Group By sec = id.Section Into Group _
Order By sec Ascending _
Select sec
Me.cbSection.DataSource = getSec
Me.cbSection.DataBind()
End If
End Sub
But it's not happening.
Dim getRspOff = (From id In d.tblDepts _
Group By ro = id.RespOffice Into Group _
Order By ro Ascending _
Select ro).ToList
RemoveHandler Me.PMComboBox.SelectedInde
Me.PMComboBox.DataSource = getRspOff
Me.PMComboBox.DataBind()
Me.PMComboBox.SelectedInde
AddHandler Me.PMComboBox.SelectedInde
Next I want this code to run when I select an items from the PMCombobox.
Protected Sub PMComboBox_SelectedIndexCh
Dim getDept = (From id In d.tblDepts _
Where id.RespOffice = PMComboBox.SelectedItem.Te
Group By dpt = id.Dept Into Group _
Order By dpt Ascending _
Select dpt).ToList
Me.cbDept.DataSource = getDept
Me.cbDept.DataBind()
If cbDept.Items.Count = 1 Then
Dim getSec = From id In d.tblDepts _
Where id.RespOffice = PMComboBox.SelectedItem.Te
And id.Dept = getDept.Item(0) _
Group By sec = id.Section Into Group _
Order By sec Ascending _
Select sec
Me.cbSection.DataSource = getSec
Me.cbSection.DataBind()
End If
End Sub
But it's not happening.
so, two things you should keep in mind, autopostback will be your friend. and for your page load, be sure to account for postback (if ispostback = false then)
Expanding on what you have above, if you are trying to change lables, text boxes, or other items on your selects. You will probably want to look into Update Panels. They are pretty handy for triggering updates to portions of the page without having to reload the page. I have been using them lately with lists when selection changes to change text fields and such.
so, here is a horrible example / explanation on update panels. it makes you make one, but didn't describe what it was doing very well in my opinion https://msdn.microsoft.com /en-us/lib rary/bb399 001.aspx
This one is explained more of what happens and why.
https://msdn.microsoft.com /en-us/lib rary/bb386 454.aspx?c s-save-lan g=1&cs-lan g=vb#code- snippet-1
Expanding on what you have above, if you are trying to change lables, text boxes, or other items on your selects. You will probably want to look into Update Panels. They are pretty handy for triggering updates to portions of the page without having to reload the page. I have been using them lately with lists when selection changes to change text fields and such.
so, here is a horrible example / explanation on update panels. it makes you make one, but didn't describe what it was doing very well in my opinion https://msdn.microsoft.com
This one is explained more of what happens and why.
https://msdn.microsoft.com
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
That worked!! I had fumbled around and made the PMComboBox a databound box and then the other dropboxes played well when I clicked the postback option. But the initial dropbox was still a mystery. Thanks so much for your help!
No worries Karen- glad I can help you solve your issue, please assign the points and close the question.
Cheers from Sydney,
Miguel
Cheers from Sydney,
Miguel
ASKER
Sorry, thought I did that... thanks again.
Are you using web forms?
In which page event are you running the above code? Page_Load.
Please check the example in this link.