2015-10-12 4 views
0

Salut, je suis en utilisant le code ci-dessous pour afficher une grille sur ASPXcommande de ligne ne fonctionne pas dans gridview

<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> 

et qui suit est la ligne fonction liée à la grille ci-dessus

Private Sub PhysicianGrid_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles PhysicianGrid.RowDataBound 


    If e.Row.RowType = DataControlRowType.DataRow Then 
     Dim selectLink As LinkButton = DirectCast(e.Row.FindControl("SelectedPhysician"), LinkButton) 
     Dim physId As String = e.Row.Cells(1).Text 
     If OperationType.Value.Equals("ADD ALLOCATION") Then 
      selectLink.OnClientClick() = String.Format("DisplayUpdateAllocationDivFromSearch('{0}');", physId) 
     Else 
      'selectLink.OnClientClick() = String.Format("DisplayUpdateAllocationDivFromSearchNewPhy('{0}');", physId) 
      selectLink.CommandArgument = physId 
     End If 
     selectLink.CommandArgument = physId 
    End If 
End Sub 

quand je vous cliquez sur sur le lien de sélection, l'application obtient la publication et la fonction page_load, mais sur le gestionnaire d'événement click

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 

comment puis-je l'obtenir pour frapper la fonction de commande de ligne

P.S. Je dois utiliser l'attribut EnableViewState ="False" dans la grille Je ne peux pas supprimer cet attribut. Y a-t-il une solution à ce problème?

+0

Avez-vous obtenez une erreur, si oui, alors vous devriez le mentionner ici aussi. Avez-vous essayé le mode débogage et vérifiez les valeurs de CRTypeId, Request.Form ("__ EVENTTARGET"). Contient ("SelectedPhysician") et OperationType.Value? – haraman

+0

Non je ne reçois aucune erreur juste j'ai écrit quelques lignes de code qui doivent être exécutées lorsque l'utilisateur clique sur le lien select mais en cliquant sur select link fait le post mais il ne frappe pas la commande row (son gestionnaire d'événements) . –

+0

Je ne suis pas sûr mais peut-être c'est ce code qui pose problème. Il suffit de deviner que OnClientClick et Command togather ... 'selectLink.OnClientClick()'. – haraman

Répondre

0

Voici comment je l'ai réalisé dans un projet récent, peut-être pourrait vous aider à trouver le problème. L'argument de commande a été spécifié dans l'ASPX au lieu de l'événement RowDataBound. Pour contourner le problème, vous pouvez commenter le code de votre événement RowDataBound et définir CommandArgument dans ASPX et vérifier ce qui se passe.
Je pense aussi au lieu de Request.Form("__EVENTTARGET").Contains("SelectedPhysician") vous pouvez essayer e.CommandName.Equals("SelectedPhysician")

ASPX:

<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> 

CodeBehind:

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