Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to set the Selected.Index of an asp:DropDownList in ViewState?

Status
Not open for further replies.

sa5cha

Programmer
May 29, 2001
34
DE
Hi,

can someone help me ? I need to select the correct value of an ASP:DropdownList after an autopostback ?

The following wont work :

Code:
    Protected Sub ddl_printout_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs)
        
        ddl_printout.SelectedIndex = Session("Index_ddl_printout") 
        ddl_printout.DataBind()
        
        Tabs.ActiveTabIndex = 2
        Tabs.DataBind()
    End Sub



                <asp:DropDownList ID="ddl_printout" runat="server" DataSourceID="tb_printout" 
                    DataTextField="TB_PRNT_Longname" DataValueField="TB_PRNT_Index" 
                    Width="295px" OnSelectedIndexChanged="ddl_printout_SelectedIndexChanged" 
                    AutoPostBack="True">
                </asp:DropDownList>

Thank You Sascha
 
there are couple ways
Code:
ListItem item = DropDownList.Items.FindByValue("the value")
if(item != null) item.Selected = true;
Code:
ListItem item = DropDownList.Items.FindByValue("the value")
DropDownList.SelectedIndex = DropDownList.Items.IndexOf(item)
i'm sure they're are more too.

Jason Meckley
Programmer
Specialty Bakers, Inc.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top