无法在gridview中显示已保存的数据

时间:2013-11-15 03:47:25

标签: asp.net

我在gridview中有一个下拉列表,它通过web方法获取数据,但在保存数据后,我无法在gridview中显示已保存的数据。

以下是通过web方法进行gridview绑定的代码:

 Private Sub BindData()
    Dim objTable As New DataTable("ProjectInfoClass")
    objTable = objWebService.BindProjectInfo

    projectInfoList.Clear()
    For Each dr As DataRow In objTable.Rows
        projectInfoList.Add(New ProjectInfoClass With {.ProjectNumber = dr("ProjectNumber").ToString(), .ProjectId = dr("ProjectId").ToString(), .ProjectName = dr("ProjectName").ToString(), .ProjectModifiedDate = dr("ProjectModifiedDate").ToString(), .RecordUpdatedDate = dr("RecordUpdatedDate").ToString(), .ProjectLocation = dr("ProjectLocation").ToString(), .LocationServerName = dr("LocationServerName").ToString(), .ProjectModifiedBy = dr("ProjectModifiedBy").ToString(), .DBServer = dr("DBServer").ToString(), .DBName = dr("DBName").ToString(), .Flag = Nothing})
    Next
   GridView1.DataSource = objTable
    GridView1.DataBind()
    End Sub

保存方法

 For Each objectList In projectInfoList

        If objectList.Dirty = True And objectList.Flag = Nothing Then
            objWebService.UpdateProjectInfo(objectList)
            Label1.Text = "Record updated successfully"

        ElseIf objectList.Flag = "I" And objectList.Dirty = True Then
            objWebService.InsertProjectInfo(objectList)
            Label1.Text = "Record inserted successfully"
        End If
    Next

    BindData()

    btnEdit.Enabled = True
    btnSave.Enabled = False
    btnAddNewRow.Enabled = False
End Sub

以下是绑定下拉列表的代码,它调用了web方法:

Public Sub BindDataDropDown()
     For Each grdRow As GridViewRow In GridView1.
     Dim dropDown As DropDownList = DirectCast(GridView1.Rows(grdRow.RowIndex).Cells(7).FindControl("ddlProjectModifiedBy"), DropDownList)
      dropDown.DataSource = objWebService.BindDropDown()
      dropDown.DataValueField = "EmpId"
      dropDown.DataTextField = "EmpName"
      dropDown.DataBind()
     Next
End Sub

的RowDataBound

 Protected Sub ddlProjectModifiedBy_RowDataBound(ByVal sender As Object, ByVal e As GridViewRowEventArgs)
    BindDataDropDown()
 End Sub

indexchange

 Protected Sub ddlProjectModifiedBy_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs)
    Dim gv As DropDownList = TryCast(sender, DropDownList)
    Dim row As GridViewRow = gv.Parent.NamingContainer
    Dim rowindex As Integer = row.RowIndex
    projectInfoList.Item(rowindex).ProjectModifiedBy = gv.SelectedItem.ToString()
    projectInfoList.Item(rowindex).Dirty = True
End Sub

我应该在网格的rowbound事件中写什么来保存gridview中下拉列表的选定数据?

1 个答案:

答案 0 :(得分:0)

成功将更改保存到数据库后,调用下拉绑定方法BindDataDropDown()