Home All Groups Group Topic Archive Search About

set dropdownlist value in datalist

Author
8 Apr 2005 4:12 AM
lydia sista via DotNetMonster.com
hi!
does anyone know how to set dropdownlist value in datalist?
here's my code..
in editprofile.aspx:

<asp:datalist id=mydl runat=server>
<asp:dropdownlist id=title runat=server>
<asp:listitem value="ms.">ms.</asp:listitem>
<asp:listitem value="mr.">mr.</asp:listitem>
<asp:listitem value="mrs.">mrs.</asp:listitem>
<asp:listitem value="miss">miss</asp:listitem>
</asp:dropdownlist>
</asp:datalist>

Then in my editprofile.aspx.vb Page_load sub

Dim i As Integer
        For i = 0 To title.Items.Count - 1
                If title.Items(i).Value = "mr." Then
                    title.SelectedIndex = i
                    Exit For
                End If
        Next

Executing this I got error:
Object reference not set to an instance of an object.

Can anyone help ple,ase.... >_<

--
Message posted via http://www.dotnetmonster.com

Author
8 Apr 2005 12:56 PM
Brock Allen
Is this what you're looking for?

DropDownList.ClearSelection();
DropDownList.Items.FindByValue("Foo").Selected = true;

-Brock
DevelopMentor
http://staff.develop.com/ballen



Show quoteHide quote
> hi!
> does anyone know how to set dropdownlist value in datalist?
> here's my code..
> in editprofile.aspx:
> <asp:datalist id=mydl runat=server>
> <asp:dropdownlist id=title runat=server>
> <asp:listitem value="ms.">ms.</asp:listitem>
> <asp:listitem value="mr.">mr.</asp:listitem>
> <asp:listitem value="mrs.">mrs.</asp:listitem>
> <asp:listitem value="miss">miss</asp:listitem>
> </asp:dropdownlist>
> </asp:datalist>
> Then in my editprofile.aspx.vb Page_load sub
>
> Dim i As Integer
> For i = 0 To title.Items.Count - 1
> If title.Items(i).Value = "mr." Then
> title.SelectedIndex = i
> Exit For
> End If
> Next
> Executing this I got error:
> Object reference not set to an instance of an object.
> Can anyone help ple,ase.... >_<
>

Bookmark and Share