|
-
Jun 27th, 2003, 01:41 PM
#1
Thread Starter
PowerPoster
Can't use DropDown in DataList
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?
Code:
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
-
Jun 27th, 2003, 10:48 PM
#2
Addicted Member
You are missing part of your code:
Code:
Sub Edit_Command(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataListCommandEventArgs) Handles DataList1.EditCommand
Should be:
Code:
Private Sub Datalist1_EditCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataListCommandEventArgs) Handles DataList1.EditCommand
-
Jun 30th, 2003, 08:29 AM
#3
Thread Starter
PowerPoster
This works from Microsoft.
Code:
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
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|