Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/34.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net 行命令在gridview中不起作用_Asp.net_Vb.net_Gridview_Rowcommand - Fatal编程技术网

Asp.net 行命令在gridview中不起作用

Asp.net 行命令在gridview中不起作用,asp.net,vb.net,gridview,rowcommand,Asp.net,Vb.net,Gridview,Rowcommand,您好,我正在使用以下代码在aspx上显示网格 <asp:GridView Caption="Search Results" ID="PhysicianGrid" runat="server" EnableSortingAndPagingCallbacks="false" PageSize="5" Style="width: 100%" PagerSettings-Visible="false"

您好,我正在使用以下代码在aspx上显示网格

 <asp:GridView Caption="Search Results" ID="PhysicianGrid"
                        runat="server" EnableSortingAndPagingCallbacks="false" PageSize="5" Style="width: 100%"
                        PagerSettings-Visible="false" AutoGenerateColumns="false" CssClass="grid" RowStyle-CssClass="gridDataRow"
                        HeaderStyle-CssClass="headerRow" EnableViewState ="False">
                        <Columns>
                            <asp:TemplateField HeaderText="Select">
                                <HeaderStyle Width="70px" HorizontalAlign="Center" />
                                <ItemStyle HorizontalAlign="Center" />
                                <ItemTemplate>
                                    <asp:LinkButton ID="SelectedPhysician" runat="server" Text="Select" CommandName="SelectAffiliation" />
                                </ItemTemplate>
                            </asp:TemplateField>
                            <asp:BoundField HeaderText="Physician ID" DataField="AMDM_Phys_ID" HeaderStyle-HorizontalAlign="Left"
                                ItemStyle-HorizontalAlign="Left" HeaderStyle-Width="70px" ItemStyle-Width="70px" />
                        </Columns>
                    </asp:GridView>
当我点击select链接时,应用程序得到回发并点击page_load函数,但点击事件处理程序

Private Sub PhysicianGrid_Command(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCommandEventArgs) Handles PhysicianGrid.RowCommand
    If _requestView.CRTypeId = Resources.PageResources.CRTYPEAddNewPhysician AndAlso Request.Form("__EVENTTARGET").Contains("SelectedPhysician") AndAlso OperationType.Value.Equals("ADD NEW PHY") Then

        Dim selectedPhys As Integer = CInt(e.CommandArgument)
        Dim tempPhys As PhysicianView = New PhysicianView
        tempPhys.LoadSearchPhysician(Master.Environment, selectedPhys, True)
        Dim dt As ShipToDetailsDataSet.AMU_SHIPTO_ALLOCATION_VDataTable = New ShipToDetailsDataSet.AMU_SHIPTO_ALLOCATION_VDataTable
        If allocationOperation.Value.Equals("UPDATE") Then
            If GridSelectedShipToAllocations.Rows.Count > 0 Then
                For Each row As GridViewRow In GridSelectedShipToAllocations.Rows

                    Dim allocationString As String = DirectCast(row.FindControl("TextBoxNewAllocation"), TextBox).Text
                    SaveGridAllocationChangeForPostback(allocationString)
                    dt.AddAMU_SHIPTO_ALLOCATION_VRow(CInt(_shipToID), CInt(row.Cells(GridSelectedShipToAllocations_columns.colAMDM_PHYS_ID).Text), row.Cells(GridSelectedShipToAllocations_columns.colPhysician_Name).Text, Nothing, CDec(row.Cells(GridSelectedShipToAllocations_columns.colAllocation).Text.Substring(0, row.Cells(GridSelectedShipToAllocations_columns.colAllocation).Text.Length - 1)), CDate("01/01/2007"), Nothing, "", "", "", row.Cells(GridSelectedShipToAllocations_columns.colMajorSpec).Text.Replace("&nbsp;", ""), row.Cells(GridSelectedShipToAllocations_columns.colSecondarySpecialty).Text.Replace("&nbsp;", ""), row.Cells(GridSelectedShipToAllocations_columns.colTertiarySpecialty).Text.Replace("&nbsp;", ""), "", "", "", "")
                Next
            End If
            dt.AddAMU_SHIPTO_ALLOCATION_VRow(CInt(_shipToID), tempPhys.PhysicianID, String.Format("{0}, {1} {2}", tempPhys.LastName, tempPhys.FirstName, tempPhys.MiddleName), Nothing, 0, CDate("01/01/2007"), Nothing, tempPhys.StatusId, tempPhys.FirstName, tempPhys.LastName, tempPhys.MajorSpec, tempPhys.SECONDARY_SPECIALTY_LD, tempPhys.TERTIARY_SPECIALTY_LD, "", "", "", "")
            GridSelectedShipToAllocations.DataSource = dt
            GridSelectedShipToAllocations.DataBind()
            GridSelectedShipToAllocations.Style("display") = "block"
            'DivAddAllocationChange.Style("display") = "none"
            LabelTotal.Style("display") = "block"
            ScriptManager.RegisterStartupScript(Me.PhysicianGrid, GetType(Page), "hideSearchPhysDiv", "DisplayUpdateAllocationDivFromSearchNewPhy('" + selectedPhys.ToString + "');", True)

        End If

    End If

End Sub
我如何让它点击row命令函数


另外,我需要在网格中使用EnableViewState=False属性,我无法删除该属性。这个问题有什么解决方法吗?

这是我在最近的一个项目中实现它的方法,也许它可以帮助您找到问题所在。已在ASPX而不是RowDataBound事件中指定命令参数。 作为解决方法,您可以只注释掉RowDataBound事件中的代码,并在ASPX中设置CommandArgument,然后检查发生了什么。 此外,我认为您可以尝试e.CommandName.EqualsSelectedMedicine,而不是Request.Form\u EVENTTARGET.containsSelectedMedicine

ASPX:


你是否有任何错误,如果有,那么你也应该在这里提及。您是否尝试过调试模式并检查了CRTypeId的值,Request.Form\uuu EVENTTARGET.containsselectedMedicine和OperationType.Value?不,我没有收到任何错误,只是我编写了几行代码,当用户单击选择链接时需要执行这些代码,但单击选择链接正在执行回发,但它没有点击行命令及其事件处理程序。我不确定,可能是这样的导致问题的代码。只是一个猜测,一旦客户端单击并命令在一起。。。选择link.OnClientClick。
Private Sub PhysicianGrid_Command(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCommandEventArgs) Handles PhysicianGrid.RowCommand
    If _requestView.CRTypeId = Resources.PageResources.CRTYPEAddNewPhysician AndAlso Request.Form("__EVENTTARGET").Contains("SelectedPhysician") AndAlso OperationType.Value.Equals("ADD NEW PHY") Then

        Dim selectedPhys As Integer = CInt(e.CommandArgument)
        Dim tempPhys As PhysicianView = New PhysicianView
        tempPhys.LoadSearchPhysician(Master.Environment, selectedPhys, True)
        Dim dt As ShipToDetailsDataSet.AMU_SHIPTO_ALLOCATION_VDataTable = New ShipToDetailsDataSet.AMU_SHIPTO_ALLOCATION_VDataTable
        If allocationOperation.Value.Equals("UPDATE") Then
            If GridSelectedShipToAllocations.Rows.Count > 0 Then
                For Each row As GridViewRow In GridSelectedShipToAllocations.Rows

                    Dim allocationString As String = DirectCast(row.FindControl("TextBoxNewAllocation"), TextBox).Text
                    SaveGridAllocationChangeForPostback(allocationString)
                    dt.AddAMU_SHIPTO_ALLOCATION_VRow(CInt(_shipToID), CInt(row.Cells(GridSelectedShipToAllocations_columns.colAMDM_PHYS_ID).Text), row.Cells(GridSelectedShipToAllocations_columns.colPhysician_Name).Text, Nothing, CDec(row.Cells(GridSelectedShipToAllocations_columns.colAllocation).Text.Substring(0, row.Cells(GridSelectedShipToAllocations_columns.colAllocation).Text.Length - 1)), CDate("01/01/2007"), Nothing, "", "", "", row.Cells(GridSelectedShipToAllocations_columns.colMajorSpec).Text.Replace("&nbsp;", ""), row.Cells(GridSelectedShipToAllocations_columns.colSecondarySpecialty).Text.Replace("&nbsp;", ""), row.Cells(GridSelectedShipToAllocations_columns.colTertiarySpecialty).Text.Replace("&nbsp;", ""), "", "", "", "")
                Next
            End If
            dt.AddAMU_SHIPTO_ALLOCATION_VRow(CInt(_shipToID), tempPhys.PhysicianID, String.Format("{0}, {1} {2}", tempPhys.LastName, tempPhys.FirstName, tempPhys.MiddleName), Nothing, 0, CDate("01/01/2007"), Nothing, tempPhys.StatusId, tempPhys.FirstName, tempPhys.LastName, tempPhys.MajorSpec, tempPhys.SECONDARY_SPECIALTY_LD, tempPhys.TERTIARY_SPECIALTY_LD, "", "", "", "")
            GridSelectedShipToAllocations.DataSource = dt
            GridSelectedShipToAllocations.DataBind()
            GridSelectedShipToAllocations.Style("display") = "block"
            'DivAddAllocationChange.Style("display") = "none"
            LabelTotal.Style("display") = "block"
            ScriptManager.RegisterStartupScript(Me.PhysicianGrid, GetType(Page), "hideSearchPhysDiv", "DisplayUpdateAllocationDivFromSearchNewPhy('" + selectedPhys.ToString + "');", True)

        End If

    End If

End Sub
<asp:GridView ID="gvStudents" runat="server" AutoGenerateColumns="false">
  <Columns>
    ...
    <asp:TemplateField>
      <ItemTemplate>
        <asp:LinkButton ID="BtnUnlock" runat="server" Text="Unlock" CausesValidation="True" CommandName="UnlockProfile" CommandArgument='<%# Eval("User_ID") %>' />
      </ItemTemplate>
    </asp:TemplateField>
    ...
  </Columns>
</asp:GridView>
Private Sub gvStudents_RowCommand(sender As Object, e As System.Web.UI.WebControls.GridViewCommandEventArgs) Handles gvStudents.RowCommand
    If e.CommandName.Equals("UnlockProfile") Then
        Dim lnUser_ID As Integer = Convert.ToInt32(e.CommandArgument)
        ...
    ElseIf e.CommandName.Equals("LockProfile") Then
        ...
    End If
End Sub