开发者

how to set the value of a dropdown to its default always

开发者 https://www.devze.com 2023-03-12 12:27 出处:网络
A Page has Repeater Control displays students records, when click on any record it displays total info, this page has a dropdownlist and other controls contained in panel set to visible false.When the

A Page has Repeater Control displays students records, when click on any record it displays total info, this page has a dropdownlist and other controls contained in panel set to visible false. When the user search it displays the students info [ 10 rows ] it displays SSN, FName, LName开发者_如何学运维,DOB when he wants to see the more detail description of the student he clicks on that student row , then we make panel to be visible it has a dropdown and set its dataTextfield to all the departments from the database. Here i want to display the dropdown to its default "Select deptartment" he selects any dept and clicks "SAVE" then page reloads and it again it should set to its default value "Select deptartment"....this one i am unable to do this

i did this way dd.items,insert(0,"Select deptartment").....> with this each time page reloads this item is added to dropdown and i tried

dd.selectedindex= 0

as the data items are coming from database..we cannot set the value to its default.


In the DataBound event of your dropdownlist can't you just use the dd.selectedValue = TheValue where TheValue is the string value you gave to the "Select Department" item when you added it to the DDL?


Use this line of code it will work,

            Conn.Open()
            dr= cmd.ExecuteReader(CommandBehavior.CloseConnection)
            dd.DataSource = dr
            dd.DataValueField = "ColumnName"
            dd.DataBind()
            dd.Items.Insert(0, "-----Select department-----")
            Conn.Close()


Use Below :

<asp:DropDownList ID="dd" runat="server" AppendDataBoundItems="True" Width="133px" AutoPostBack="True" OnSelectedIndexChanged="dd_SelectedIndexChanged">
                    <asp:ListItem Value="-1">[Select]</asp:ListItem>
                </asp:DropDownList>

dd.SelectedIndex = 0;
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号