c# - DropDownList selected value not getting set -


I am using two dropdowns for the month and year selection, I have created a user control and I have a control The criminal is getting inside the control. I have to show the values ​​selected from the database from them. For example, if it is 5/2014 in the database then it should be shown in May drop down and in the year drop down in May. I am doing this in a roadbound incident but it is not being selected. I am doing this way

  var txtFrom = e.item.FindControl ("txfrom") text box form In; // I have the mm / yyy var datefrom = e.Item.FindControl will be the value I ("Ddempfrom") as CutomControls.MonthYearPicker; Var monthfrom = datefrom1.FindControl ("ddmonth") as DropDownList; Var yearfrom = datefrom1.FindControl ("ddyear") as DropDownList; monthfrom.SelectedValue = txtFrom.Text.Split ('/') [0]; From the year Selected vla = txtFrom.Text.Split ('/') [1];   

And it is that I am creating a dropdown list for user zeros () (for int i = 1; I & lt; = 12; I ++) {DateTime = New Date Time (1900, 1, 1); Ddmonth.Items.Add (New system. Web.UI.WebControls.ListItem (date.ToString ("MMMM"), i.ToString ())); } var currentYear = DateTime.Now; (Int i = 1900; i & lt; = convert toint32 (current era. Toaster ("yyyy"); i ++) {ddyear.Items.Add (new system .web.webcontrols. ListItem (i.ToString (), i.ToString ())); }} Secure Zero Page_load (Object Sender, EventAgds E) {if (! Page. ISPostback) Load Monotheeer (); }

I tried debugging and when the brake is on the point line where I am setting the selected value, after going to the next line, the selected value appears to be empty. >

My dropdown lists

  & asp: dropdown list id = "ddmonth" runat = "server" & gt; & Lt; / ASP: DropDownList & gt; - & lt; asp: dropdown list id = "ddyear" runat = "server" & gt; & Lt; / ASP: DropDownList & gt;   

Update: I have noticed that RodeDatabound is hit first, then user coding is Page_Load hiting

When you put an example on your dropdown in your user control, an OnDataBinding event handler

  & lt; Asp: dropdown list id = "ddlmonth" runat = "server" OnDataBinding = "ddlMonth_DataBinding" & gt; & Lt; / ASP: DropDownList & gt; & Lt; Asp: dropdown list id = "ddyear" runat = "server" OnDataBinding = "ddlYear_DataBinding" & gt; & Lt; / ASP: DropDownList & gt;   

and then create event handlers in the code behind the user's controller

  secure void ddlMonth_DataBinding (Object Sender, System.EventArgs e) {DropDownList ddl = (DropDownList ) (this); For (int i = 1; i   

}

You then repeat your dropdown value onItemDataBound event

Comments

Popular posts from this blog

Java - Error: no suitable method found for add(int, java.lang.String) -

java - JPA TypedQuery: Parameter value element did not match expected type -

c++ - static template member variable has internal linkage but is not defined -