|
-
Dec 18th, 2002, 09:06 AM
#1
Thread Starter
Fanatic Member
combo problem
(Dreamweaver MX, ASP.NET, VB.NET)
I have an edit page which uses a combo box.
The user chooses an item from the combo and the value is written away to the underlying field.
The problem I have is that everytime the user goes to the webpage the 1st item is always displayed.
Is there any way I can check to see if there is a value in the underlying field and if there is force the combo to jump to that item.
Thanksin advance
-
Dec 18th, 2002, 10:09 AM
#2
Member
If you enable viewstate (.EnableViewState = True) and make sure that you're only filling the DropDownList the first time the page loads (If Not IsPostBack Then), then it will stay on the last item you selected, which is what you're going for, right?
-
Dec 18th, 2002, 10:28 AM
#3
Thread Starter
Fanatic Member
I'm not sure about this.
WHen the user first goes to the page, lets say the underlying field contains "3" which refers to the 3rd item in the combo I want the combo to display the text representing the third item.
I'll have to apologise but I'm new to all this .net code.
-
Dec 18th, 2002, 01:04 PM
#4
Member
I'm sorry, but I'm not following what you're asking for.
You know about the .DataTextField and .DataValueField properties, right?
-
Dec 18th, 2002, 05:35 PM
#5
Hyperactive Member
VB Code:
<script language="vb" runat="server">
Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
Dim myExistingValue As String = "item2"
If myExistingValue <> "" Then
If Not myDropDownList.Items.FindByValue(myExistingValue) Is Nothing Then
myDropDownList.Items.FindByValue(myExistingValue).Selected = True
End If
End If
End Sub
</script>
<html>
<body>
<form id="SelectAnItem" runat="server">
<asp:DropDownList
ID="MyDropDownList"
Runat="server">
<asp:ListItem Value="item1">item1</asp:ListItem>
<asp:ListItem Value="item2">item2</asp:ListItem>
<asp:ListItem Value="item3">item3</asp:ListItem>
</asp:DropDownList>
</form>
</body>
</html>
-
Dec 19th, 2002, 09:25 AM
#6
Member
change it to this...the changed lines are bold
VB Code:
<script language="vb" runat="server">
Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
[b]If Not IsPostBack Then[/b]
Dim myExistingValue As String = "item2"
If myExistingValue <> "" Then
If Not myDropDownList.Items.FindByValue(myExistingValue) Is Nothing Then
myDropDownList.Items.FindByValue(myExistingValue).Selected = True
End If
End If
[b]End If[/b]
End Sub
</script>
<html>
<body>
<form id="SelectAnItem" runat="server">
<asp:DropDownList
ID="MyDropDownList"
Runat="server"
[b]AutoPostBack="True">[/b]
<asp:ListItem Value="item1">item1</asp:ListItem>
<asp:ListItem Value="item2">item2</asp:ListItem>
<asp:ListItem Value="item3">item3</asp:ListItem>
</asp:DropDownList>
</form>
</body>
</html>
The way you had it, it would set the selected item to "item2" every time and would never change.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|