PDA

Click to See Complete Forum and Search --> : Can't use DropDown in DataList


jesus4u
Jun 27th, 2003, 01:41 PM
I have a dropdown list inside the EditItemTemplate that I need to execute this code against. Problem is that the e can not find my control. What is up?


Sub Edit_Command(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataListCommandEventArgs) Handles DataList1.EditCommand
DataList1.EditItemIndex = e.Item.ItemIndex
Dim dwntype As DropDownList
dwntype = CType(e.Item.FindControl("dwnType"), DropDownList)
dwntype.SelectedItem.Selected = False
Dim t As String = "Department Announcement"
dwntype.Items.FindByValue(t.ToString()).Selected = True
LoadData()
End Sub

rdove
Jun 27th, 2003, 10:48 PM
You are missing part of your code:
Sub Edit_Command(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataListCommandEventArgs) Handles DataList1.EditCommand
Should be:
Private Sub Datalist1_EditCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataListCommandEventArgs) Handles DataList1.EditCommand

jesus4u
Jun 30th, 2003, 08:29 AM
This works from Microsoft.


Private Sub DataList1_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataListItemEventArgs) Handles DataList1.ItemDataBound
If e.Item.ItemType = ListItemType.EditItem Then
Dim drv As DataRowView = CType(e.Item.DataItem, DataRowView)
Dim currentgenre As String = CType(drv("TypeName"), String)' Name of the item you are looking for
Dim ddl As DropDownList
ddl = CType(e.Item.FindControl("dwnType"), DropDownList)' Name of the control you are looking for
ddl.SelectedIndex = ddl.Items.IndexOf(ddl.Items.FindByText(currentgenre))' Here is where it preselects the control
End If
End Sub