Results 1 to 3 of 3

Thread: Can't use DropDown in DataList

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Jan 2001
    Location
    Florida
    Posts
    3,216

    Angry 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

  2. #2
    Addicted Member rdove's Avatar
    Join Date
    Dec 2002
    Location
    Indianapolis
    Posts
    251
    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
    ~Ryan





    Have I helped you? Please Rate my posts.

  3. #3

    Thread Starter
    PowerPoster
    Join Date
    Jan 2001
    Location
    Florida
    Posts
    3,216
    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
  •  



Click Here to Expand Forum to Full Width