把datagrid里面的第四列的第一个控件转换为DropDownList //编辑的时候用

解决方案 »

  1.   

    把datagrid里面的第四列的第一个控件转换为DropDownList 
    得到实例 DDL   ,用DDL就可以操作了
      

  2.   

    DropDownList DDL= (DropDownList)(e.Item.Cells[4].Controls[1], DropDownList);
    DropDownList DDL= CType(e.Item.Cells(4).Controls(1), DropDownList);
    语法错误
      

  3.   

    DropDownList DDL= (DropDownList)(e.Item.Cells[4].Controls[1]);
    DropDownList DDL= CType(e.Item.Cells(4).Controls(1), DropDownList);
    语法错误
      

  4.   

    但我在调试的时候出现错误,说CType在类或命名空间中不存在。why,还需要引入什么命名空间?
      

  5.   

    我改成
    DropDownList DDL= (DropDownList)(e.Item.Cells[4].Controls[1], DropDownList);
    后,还是有错误:
    “System.Web.UI.WebControls.DropDownList”表示“类”,此处应为“变量”
      

  6.   

    CType是VB.NET中的语法
    C#中的正确语法,就像孟子说的那样
      

  7.   

    DropDownList DDL= (DropDownList)(e.Item.Cells[4].Controls[1]);
      

  8.   

    哪位高手能不能把下边这段用vb写的代码改成c#,特别是函数头那段。多谢!!
    Private Sub DataGrid1_ItemDataBound(ByVal sender As Object, _
    ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs) _ 
    Handles DataGrid1.ItemDataBound
     If e.Item.ItemType = ListItemType.EditItem Then
      Dim DRV As DataRowView = CType(e.Item.DataItem, DataRowView)
      Dim CurrentShip As String = DRV("ShipVia")
      Dim DDL As DropDownList = CType(e.Item.Cells(4).Controls(1), DropDownList)
      Dim SQL As String = "SELECT ShipperID, CompanyName FROM Shippers ORDER BY ShipperID"
      Dim DA As SqlDataAdapter = New SqlDataAdapter(SQL, ConnStr)
      Dim DS As New DataSet
      Dim item As ListItem
      DA.Fill(DS, "Shippers")
      DDL.DataSource = DS.Tables("Shippers").DefaultView
      DDL.DataTextField = "CompanyName"
      DDL.DataValueField = "ShipperID"
      DDL.DataBind()
      item = DDL.Items.FindByValue(CurrentShip)
     If Not item Is Nothing Then item.Selected = True
     End If
    End Sub
      

  9.   

    DropDownList DDL= (DropDownList)(e.Item.Cells[4].FindControl("ID"));