first take a look at attachment pic to get a idea.
I have two dropDownLists.1st dropDownList ID is cboPrev(oPrev) and 2nd dropDownList ID is cboNext(oNext).
These both DropDownList will have the following 4 items (2014, 2015, 2016, 2017). User can click on dropdownlist and pick a year.
problem:
so for default item on dropDownList is "2014" but when user click on "2016" than the default first item is still "2014" - which is wrong
What I want:
So for default item on dropDownList is "2014" but when user click on "2016" than the default first item in dropDownList should be "2016". I want the defualt item in dropDownList what every user select. How can I do this in vb .net?
Protected Sub dlCalendar_ItemDataBound(ByVal sender As Object, ByVal e As DataListItemEventArgs)
' Just populationg my header section
Dim dDate As DateTime
dDate = DateTime.Now
If e.Item.ItemType = ListItemType.Header Then
Dim oPrev As DropDownList = DirectCast(e.Item.FindControl("cboPrev"), DropDownList)
Dim oNext As DropDownList = DirectCast(e.Item.FindControl("cboNext"), DropDownList)
Dim dtYear As New DataTable()
dtYear.Columns.Add("year4")
dtYear.Columns.Add("sValue")
' store iteams in DropDownList: 2014, 2015, 2016, 2017
dtYear.Rows.Add(DateTime.Now.AddYears(-1).ToString("yyyy"), "01 Jan," & DateTime.Now.AddYears(-1).ToString("yyyy"))
dtYear.Rows.Add(DateTime.Now.ToString("yyyy"), DateTime.Now.ToString("dd MMM, yyyy"))
dtYear.Rows.Add(DateTime.Now.AddYears(1).ToString("yyyy"), "01 Jan," & DateTime.Now.AddYears(1).ToString("yyyy"))
dtYear.Rows.Add(DateTime.Now.AddYears(2).ToString("yyyy"), "01 Jan," & DateTime.Now.AddYears(2).ToString("yyyy"))
'bind data
oPrev.DataTextField = "year4"
oPrev.DataValueField = "sValue"
oPrev.DataSource = dtYear
oPrev.DataBind()
oNext.DataTextField = "year4"
oNext.DataValueField = "sValue"
oNext.DataSource = dtYear
oNext.DataBind()
'left(mm yyyy) - middle(mm yyyy) - right(mm yyyy)
'click on link and it stay that year
DirectCast(e.Item.FindControl("lblLeft"), Label).Text = "<a style=color:Black href=Calendar.aspx?id=" & Request.QueryString("id") & "&SpecificMonth=" & dDate.AddMonths(-1).ToString("dd-MMMM-yyyy") & ">" & dDate.AddMonths(-1).ToString("MMMM yyyy") & "</a>"
DirectCast(e.Item.FindControl("lblMiddle"), Label).Text = dDate.ToString("MMMM yyyy")
DirectCast(e.Item.FindControl("lblRight"), Label).Text = "<a style=color:Black href=Calendar.aspx?id=" & Request.QueryString("id") & "&SpecificMonth=" & dDate.AddMonths(+1).ToString("dd-MMMM-yyyy") & ">" & dDate.AddMonths(+1).ToString("MMMM yyyy") & "</a>"
End If
End Sub
Protected Sub RfreshData(ByVal sender As Object, ByVal e As System.EventArgs)
'redirect by date thats why page can render the calendar according to user selection
Response.Redirect("Calendar.aspx?id=" & Request.QueryString("id") & "&SpecificMonth=" + DirectCast(sender, DropDownList).SelectedValue)
End Sub