Forum Moderators: open
I have an ASP.NET page (coded in C#) which contains both a datagrid (dgChoice) and a dropdown list(dlChoose). Everytime a user chooses a different option in the dropdown list, different data corresponding to this choice is loaded into the dgChoice with help from a function that looks like this:
private void dlChoose_SelectedIndexChanged(object s, System.EventArgs e){
string strSelected = dlChoose.SelectedItem.Value;
switch (strSelected){
case "0":
dgChoiceSource = "Path for datasource 1(default)";
break;
case "1":
dgChoiceSource = " Path for datasource 1";
break;
case "2":
dgChoiceSource = " Path for datasource 2";
break;
case "3":
dgChoiceSource= " Path for datasource 3";
break;
}
When no choices have been made, dgChoice should reflect exactly what dlChoose displays when no selections have been made (Path for datasource 1) which is the default choice for both grid and dropdown.
The problem is that this doesn’t happen. The grid(dgChoice) doesn’t show up until you changed the selection in the dropdownList(dlChoose).
How do I make it so that the grid always shows data and always corresponds to the choice in the dlChoose dropdown, even if no selections have been made?
If anyone could help with this, I’d be very grateful.
Thanks!
I think that I see what you mean, basically the grid data should be loaded anyway with their default content and the dropdown menu should show the default choice which corresponds to the grid’s default content.
That way the grid’s content only load again, if a different choice was made in the dropdownlist.
I’m getting this right?
I thought that there was a way to synchronise the dropdown’s contents and grid even prior making a choice, but obviously that cannot happen because of the postback.
Is there a way to make it happen if it is set to false? And will this affect the way in which the dropdown works for other choices?
regards
Private Sub SetComboBoxByValue(ByVal ctl As DropDownList, ByVal value As String)
Dim i As Integer
If value <> "" Then
For i = 0 To ctl.Items.Count - 1
If ctl.Items(i).Value = value Then
ctl.SelectedIndex = i
Exit Sub
End If
Next
End If
End Sub