C
Crazy Cat
Hi,
I am populating a dropdownlist in a DataList's ItemTemplate then
setting it's SelectedValue in the dropdownlist's ItemDataBound
property. However when the page is displayed the dropdownlist's
Selected Value is set to the largest value so that the bottom
selection appears selected. I actually printed out the SelectedValues
in the ItemDataBound and the PreRender events and can see that the
values change between the two events.
Here's the code --- (Importances is a collection of DataListItems)
Protected Sub dlIncentives_ItemDataBound(ByVal sender As Object,
ByVal e As System.Web.UI.WebControls.DataListItemEventArgs) Handles
dlIncentives.ItemDataBound
If Not IsPostBack Then
If e.Item.ItemType = ListItemType.Item Or e.Item.ItemType
= ListItemType.AlternatingItem Then
Dim ddlImportance As DropDownList =
e.Item.FindControl("ddlImportance")
For Each item As ListItem In Importances
ddlImportance.Items.Add(item)
Next
ddlImportance.SelectedValue = CType(e.Item.DataItem,
DataRowView).Row.Item("IncImp_ID")
System.Diagnostics.Debug.Print("ItemDataBound -
SelectedValue" & ddlImportance.SelectedValue)
End If
End If
End Sub
Protected Sub dlIncentives_PreRender(ByVal sender As Object, ByVal
e As System.EventArgs) Handles dlIncentives.PreRender
If Not IsPostBack Then
For Each item As DataListItem In dlIncentives.Items
Dim ddlImportance As DropDownList =
item.FindControl("ddlImportance")
System.Diagnostics.Debug.Print("PreRender -
SelectedValue" & ddlImportance.SelectedValue)
Next
End If
End Sub
My output window shows the following (the database has 4 rows of data)
-
ItemDataBound - SelectedValue 2
ItemDataBound - SelectedValue 5
ItemDataBound - SelectedValue 2
ItemDataBound - SelectedValue 6
PreRender - SelectedValue 6
PreRender - SelectedValue 6
PreRender - SelectedValue 6
PreRender - SelectedValue 6
Magically, between the ItemDataBound event and the PreRender event the
SelectedValue changes!!!!
What the F---!?!
Another MicroShaft "undocumented" "feature" I guess.
Can anyone help?
Thanks,
I am populating a dropdownlist in a DataList's ItemTemplate then
setting it's SelectedValue in the dropdownlist's ItemDataBound
property. However when the page is displayed the dropdownlist's
Selected Value is set to the largest value so that the bottom
selection appears selected. I actually printed out the SelectedValues
in the ItemDataBound and the PreRender events and can see that the
values change between the two events.
Here's the code --- (Importances is a collection of DataListItems)
Protected Sub dlIncentives_ItemDataBound(ByVal sender As Object,
ByVal e As System.Web.UI.WebControls.DataListItemEventArgs) Handles
dlIncentives.ItemDataBound
If Not IsPostBack Then
If e.Item.ItemType = ListItemType.Item Or e.Item.ItemType
= ListItemType.AlternatingItem Then
Dim ddlImportance As DropDownList =
e.Item.FindControl("ddlImportance")
For Each item As ListItem In Importances
ddlImportance.Items.Add(item)
Next
ddlImportance.SelectedValue = CType(e.Item.DataItem,
DataRowView).Row.Item("IncImp_ID")
System.Diagnostics.Debug.Print("ItemDataBound -
SelectedValue" & ddlImportance.SelectedValue)
End If
End If
End Sub
Protected Sub dlIncentives_PreRender(ByVal sender As Object, ByVal
e As System.EventArgs) Handles dlIncentives.PreRender
If Not IsPostBack Then
For Each item As DataListItem In dlIncentives.Items
Dim ddlImportance As DropDownList =
item.FindControl("ddlImportance")
System.Diagnostics.Debug.Print("PreRender -
SelectedValue" & ddlImportance.SelectedValue)
Next
End If
End Sub
My output window shows the following (the database has 4 rows of data)
-
ItemDataBound - SelectedValue 2
ItemDataBound - SelectedValue 5
ItemDataBound - SelectedValue 2
ItemDataBound - SelectedValue 6
PreRender - SelectedValue 6
PreRender - SelectedValue 6
PreRender - SelectedValue 6
PreRender - SelectedValue 6
Magically, between the ItemDataBound event and the PreRender event the
SelectedValue changes!!!!
What the F---!?!
Another MicroShaft "undocumented" "feature" I guess.
Can anyone help?
Thanks,