在DataBound中实现
和平时用的没有两样.
就是注意实例化你的DropdwonList

解决方案 »

  1.   

    但是第一个dropdownlist的触发事件如何写呢。没有触发事件无法让第二个绑定dropdownlist绑定数据。
    dropdownlist是datagrid里的模板
      

  2.   

    我也很想知道 怎么触发这个事件? 在datagrid里面怎么触发
      

  3.   

    在 ItemCreated 事件里写:
    if(e.Item .ItemType ==ListItemType.Header )
    {
    DropDownList dep=(DropDownList)e.Item .FindControl ("dept");
    dep.SelectedIndexChanged+=new EventHandler(dep2_SelectedIndexChanged);
      

  4.   

    sorry:if(e.Item .ItemType ==ListItemType.Item )
    ===============>
    if(e.Item.ItemType==ListItemType.Item||e.Item.ItemType ==ListItemType.AlternatingItem)
      

  5.   

    private void dep2_SelectedIndexChanged(object sender, EventArgs e)
      {
        ....
      }
      

  6.   

    我写过一个,不过我在PAGELOAD中写的,
      

  7.   

    pageload :
    For i = 0 To n
                AddHandler CType(dgListArticle.Items(i).Cells(5).FindControl("DropDownList1"), DropDownList).SelectedIndexChanged, AddressOf DropDownList1_selectchange
            Nextprivate sub DropDownList1_selectchange(ByVal sender As Object, ByVal e As System.EventArgs)
    binddrop2(CType(sender, DropDownList).SelectedItem.Text)
    end sub
      

  8.   

    还是不明白  coffeewar(苦咖啡)的 private void dep2_SelectedIndexChanged(object sender, EventArgs e) 中
    怎么把 第一个dropdownlist 的参数传递给第二个 dropdownlist呢
      

  9.   

    Private Sub Dg_ItemDataBound(ByVal sender As System.Object, ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs)        If e.Item.ItemType = ListItemType.AlternatingItem Or e.Item.ItemType = ListItemType.Item Then ' Or e.Item.ItemType = ListItemType.EditItem Then
                '************************************                         checkbox
                Dim mycheckbox As CheckBox
                mycheckbox = e.Item.FindControl("tcb")
                Response.Write(mycheckbox.Text)
                If mycheckbox.Checked Then
                    mycheckbox.Text = "Male"
                Else
                    mycheckbox.Text = "Female"
                End If
                '************************************
                '*******************************************                   DropDownList
                Dim myLst As DropDownList = CType(e.Item.FindControl("tddl"), DropDownList)
                Dim myRow As DataRowView = CType(e.Item.DataItem, DataRowView)
                Dim lbl As RadioButton = CType(e.Item.FindControl("rdo"), RadioButton)            myLst.DataTextField = "birthday"
                myLst.DataValueField = "birthday"            myLst.DataSource = GetRoles(lbl.Text)            myLst.DataBind()
                '*******************************************
                '******************                                            labelradiobutton
                Dim myLbl As Label
                myLbl = e.Item.FindControl("lblRad")
                myLbl.Text = "<input type=radio name='myradiogroup' value=" & e.Item.ItemType & ">"
                '******************        End If
            '*********************************     We only want to run this code for items in edit mode
            If (e.Item.ItemType = ListItemType.EditItem) Then
                '*********************
                'Locate our DropDownList
                Dim myList As DropDownList = CType(e.Item.FindControl("Eddl"), DropDownList)            'Grab the current row of data - we need that so we know what value to select in the ddl
                Dim myRow As DataRowView = CType(e.Item.DataItem, DataRowView)            'Set the Text and Value field for our DropDownList
                myList.DataTextField = "birthday"
                myList.DataValueField = "birthday"
                'Fill our DropDownList with the standard list of data
                myList.DataSource = GetRole()            Dim aaaa As Integer = myRow.DataView.Count()            myList.DataBind()
                myList.Items.Add("")
                myList.SelectedIndex = (aaaa - 1)
                '**********************            '******************                                          labelradiobutton
                Dim myLbl As Label
                myLbl = e.Item.FindControl("lblRad")
                myLbl.Text = "<input type=radio name='myradiogroup' value=" & "e.Item.ItemType" & ">"
                '******************            '************************************                         checkbox
                Dim mycheckbox As CheckBox
                mycheckbox = e.Item.FindControl("tcb")
                Response.Write(mycheckbox.Text)
                If mycheckbox.Checked Then
                    mycheckbox.Text = "Male"
                Else
                    mycheckbox.Text = "Female"
                End If
                '************************************        End If
            '*********************************    End Sub
       Public Function GetRole() As DataView
            StrSql = "SELECT "
            StrSql = StrSql & "birthday "
            StrSql = StrSql & "FROM MTXL "
            Dim Comm As OleDbDataAdapter = New OleDbDataAdapter(StrSql, Str)
            Dim ds As DataSet = New DataSet()
            Comm.Fill(ds, "Roles")
            Return ds.Tables("Roles").DefaultView
        End Function    Public Function GetRoles(ByVal aaa As String) As DataView
            StrSql = "SELECT "
            StrSql = StrSql & "birthday "
            StrSql = StrSql & "FROM MTXL "
            StrSql = StrSql & "where id='" & aaa & "'"
            Dim Comm As OleDbDataAdapter = New OleDbDataAdapter(StrSql, Str)
            Dim ds As DataSet = New DataSet()
            Comm.Fill(ds, "Roles")
            Return ds.Tables("Roles").DefaultView
        End Function
      

  10.   

    这样的功能我具体没有实现过,只是有个思路不知道可不可行。
    1.在 DataGrid的 ItemCreated 事件中为每行的 dropDownList1 和 dropDownList2 的 SelectedIndexChanged 事件 委托,并且绑定 dropDownList1。
    在 ItemCreated 事件里写:
    if(e.Item .ItemType ==ListItemType.Header )
    {
    DropDownList dropDownList1=(DropDownList)e.Item .FindControl ("dropDownList1");
    dropDownList1.SelectedIndexChanged+=new EventHandler(dropDownList1_SelectedIndexChanged);
    DropDownList dropDownList2=(DropDownList)e.Item .FindControl ("dropDownList2");
    dropDownList2.SelectedIndexChanged+=new EventHandler(dropDownList2_SelectedIndexChanged);2.在 dropDownList1 的 SelectedIndexChanged事件里面绑定相应行的 dropDownList1 至于怎么样将 dropDownList1 的选择的值传到 dropDownList2 可以用 dropDownList1.Parent.Parent 找到相应的行即 DataGrid.Item,知道了 Item 即可用 FindControl("ID")找到你想要的任何 web 控件。
      

  11.   

    又写错了
    if(e.Item .ItemType ==ListItemType.Header )
    改成
    if(e.Item.ItemType==ListItemType.Item||e.Item.ItemType ==ListItemType.AlternatingItem)
    我只会 C# ,VB不懂
      

  12.   

    用两个模板列放置两个DropDownlist,将第一个的AutoPostBack设为True,先用FindControl方法找到第一个DropDownList,绑定数据库,再找到第二个DropDownList根据第一个的选择,将相应的Item设为True,这两个事件都在_ItemDataBound里写