asp.net - DropDownList binding problem -
I have two dropdown listboxes called DDLD and the second DDLM. As their name suggests, DDLDA has a value of 1 to 31 (not moving) and DDLmont has a value of 1 to 12. These values are not dynamically set.
When the page loads, I am using the value of the value from the ddlDay.SelectedItem.Value = db , depending on the value of the DB .. and the item Will choose.
I provide the code
However, when the page is loaded for the first time, nothing happens. But if I refresh the page and therefore the cause of a postback, the value is tied correctly.
Protected sub page_Load (ByVal, as the object, byVal E. System.EventArgs) Handle Me.Load loadInterview () End Sub Personal SubloadInterview () If Request.QueryString (" IID ") =" "or Request.QueryString (" idid ") (interviews_list.aspx"), but if there is nothing in the form of a semi-integer new hh then the Response.Redirect is ". Interview Integer = hh.Interviews.ReturnSingleInterview (Request.QueryString ("IID") ddlDay.SelectedItem.Value = int.InterviewDate.Day.ToString ("00") ddlMonth.SelectedItem.Value = int.InterviewDate.Month.ToString ( "00") txtYear.Text = int.InterviewDate.Year txtPerson.Text = int.InterviewPerson txtTitle.Text = int.InterviewTitle txtText.Text = int.InterviewText end then
Try this to set the initial value:
ddld ay.ClearSelection () ddlDay.Items.FindByValue ( Int.InterviewDate.Day.ToString ("00")). Selected = true ddlMonth.ClearSelection () ddlMonth.Items.FindByValue (int.InterviewDate.Month.ToString ("00"). Selected = true Note: ClearSelection avoids the HTTP exception exception with the method 'Multiple items can not be selected in the dropdown list.' Message.
Edit 2: Suppose you have this dropdown The list is:
& asp: dropdown list id = "ddlItems" runat = "server"> & lt; asp: ListItem text = "item1" value = "item1" & Gt; & lt; / asp: ListItem & gt; & lt; asp: ListItem text = "item 2" value = "item 2" select Gt; & lt; asp: ListItem & gt; asp: ListItem text = "item 3" value = "item 3" & gt; & lt; / asp: ListItem & gt; Lt; / ASP: DropDownList & gt; You set your item to "ddl". .Value = "item 1"
Your dropdown list becomes like that:
& asp: dropdown list id = "ddlItems" runat = "Server" & gt; & Lt; Asp: ListItem text = "item 1" value = "item 1" & gt; & Lt; / Asp: ListItem & gt; & Lt; Asp: ListItem text = "item 2" value = "item 1" selected = "true" & gt; & Lt; / Asp: ListItem & gt; & Lt; Asp: ListItem text = "item 3" value = "item 3" & gt; & Lt; / Asp: ListItem & gt; & Lt; / ASP: DropDownList & gt; I mean ddlItems.SelectedItem refers to the selected items of your dropdown.
Comments
Post a Comment