0

我有关于子网格视图(ListView 中的网格视图)的问题,到目前为止我解决了数据绑定和删除命令,但我无法弄清楚 Edut 模式(我单击图像按钮)但 GV 没有去编辑模式代码如下:提前致谢

页面标记:

编辑项目模板

 <asp:ImageButton ID="imgbUpdate" runat="server" CommandName="Update" Text="Update" ImageUrl="~/Images/save_icon_mono.gif" CausesValidation="true" ValidationGroup="vgrpSaveContact"/>
 <asp:ImageButton ID="imgbCancel" runat="server" CommandName="Cancel" Text="Cancel" ImageUrl="~/Images/undo_icon_mono.gif" CausesValidation="false"/>

编辑项目模板

  <ItemTemplate>
    <table>
     <tr>
       <td> <asp:ImageButton ID="imgbEdit" runat="server" CommandName="Edit" Text="Edit" ImageUrl="~/Images/edit_icon_mono.gif" />
       </td>
       <td> <asp:ImageButton ID="imgbDelete" runat="server" CommandName="Delete" Text="Delete"  ImageUrl="~/Images/delete_icon_mono.gif"  ToolTip="Delete"/>
       </td>
        </tr>
      </table>
  </ItemTemplate>

代码 VB.NET

  Protected Sub gvSorties_RowUpdating(ByVal sender As Object, ByVal e As GridViewUpdateEventArgs)

    Dim connString As String = ConfigurationManager.ConnectionStrings("MoyensAeriensConnectionString").ConnectionString

    Dim gvTemp As GridView = DirectCast(sender, GridView)
    gvUniqueID = gvTemp.UniqueID
    'Get the value  

    Dim strSortieID As String = DirectCast(gvTemp.Rows(e.RowIndex).FindControl("lblSortieID"), Label).Text
    Using conn As New SqlConnection
        conn.ConnectionString = connString
        conn.Open()

        Try

            Dim strSQL As String = ""
            Dim dsTemp As New SqlDataSource()
            dsTemp.ConnectionString = connString

            'Get the values stored in the text boxes
            Dim strMissionNo As String = DirectCast(gvTemp.Rows(e.RowIndex).FindControl("txtMissionNo"), TextBox).Text
            Dim strCaptain As String = DirectCast(gvTemp.Rows(e.RowIndex).FindControl("txtCaptain"), TextBox).Text
            Dim strCrew As String = DirectCast(gvTemp.Rows(e.RowIndex).FindControl("txtCrew"), TextBox).Text
            Dim strFuel As String = DirectCast(gvTemp.Rows(e.RowIndex).FindControl("txtFuel"), TextBox).Text

            'Prepare the Update Command of the DataSource control
            strSQL = "UPDATE Sortie set MissionNo = '" & strMissionNo & "'" & ",Captain = " & strCaptain & "" & ",Crew = '" & strCrew & "'" & ",Fuel = '" & strFuel & "'" & " WHERE SortieID = " & strSortieID
            dsTemp.UpdateCommand = strSQL
            dsTemp.Update()

            'Reset Edit Index
            gvEditIndex = -1

            lvODV.DataBind()
            conn.Close()
        Catch
        End Try
    End Using
End Sub

非常感谢每一个人

4

0 回答 0