2009-09-25 5 views
1

Ceci est mon ASPX:postback gridview pas posté - VS2008

<asp:UpdatePanel ID="resultPanel" runat="server" UpdateMode="Conditional"> 
<Triggers> 
    <asp:AsyncPostBackTrigger ControlID="AddDocument" /> 
</Triggers> 
<ContentTemplate> 
    <asp:GridView ID="gridView" runat="server" AutoGenerateColumns="False" EnableSortingAndPagingCallbacks="True" 
     AllowPaging="True" DataSourceID="FilesObjectDataSource" PageSize="5" OnRowCommand="gridView_RowCommand" 
     DataKeyNames="FileGuid" HorizontalAlign="Left" Width="100%" BorderStyle="Solid" 
     BorderColor="Black"> 
     <Columns> 
      <asp:BoundField DataField="RID" HeaderText="ID" ReadOnly="True"></asp:BoundField> 
      <asp:BoundField DataField="Category" HeaderText="SubCategory" ReadOnly="True"> 
      </asp:BoundField> 
      <asp:BoundField DataField="FileTypeName" HeaderText="Type" ReadOnly="True"> 
      </asp:BoundField> 
      <asp:BoundField DataField="FileGUID" Visible="false" /> 
      <asp:ButtonField Text="X" ButtonType="Button" ItemStyle-Width="20px" CommandName="DelFile"> 
       <ItemStyle Width="20px" /> 
      </asp:ButtonField> 
     </Columns> 
     <RowStyle CssClass="RowStyle" /> 
     <EmptyDataRowStyle CssClass="EmptyRowStyle" /> 
     <PagerStyle CssClass="PagerStyle" /> 
     <SelectedRowStyle CssClass="SelectedRowStyle" /> 
     <HeaderStyle CssClass="HeaderStyle" /> 
     <EditRowStyle CssClass="EditRowStyle" /> 
     <AlternatingRowStyle CssClass="AltRowStyle" /> 
    </asp:GridView> 
</ContentTemplate> 

Ceci est mon code derrière le ButtonField marqué 'X'

protected void gridView_RowCommand(Object sender, GridViewCommandEventArgs e) 
{ 
    if (e.CommandName == "DelFile") 
    { 
     //Selected Row 
     int rowIndex = Convert.ToInt32(e.CommandArgument); 

     fileGuid = new Guid(gridView.DataKeys[rowIndex].Values["FileGuid"].ToString()); 

    } 
} 

Parfois, les résultats itt dans l'objet ref n'est pas réglé et parfois ça marche. Je ne sais pas pourquoi cela se produit dans la production et pas dans le développement et les tests.

Répondre

0

Je ne sais pas si cela fait une différence, mais, mais le cas ("FileGuid")

DataKeyNames="FileGuid" 

et

fileGuid = new Guid(gridView.DataKeys[rowIndex].Values["FileGuid"].ToString()); 

ne correspond pas ("FileGUID")

<asp:BoundField DataField="FileGUID" Visible="false" /> 
0

Vous pouvez utiliser comme celui-ci pour accéder à la valeur à l'événement de commande de ligne

protected void gridView_RowCommand(object sender, GridViewCommandEventArgs e) 
{ 
    if (e.CommandName == "DelFile") 
    { 
     int index = Convert.ToInt32(e.CommandArgument); 
     int documentID = Convert.ToInt32(gridView.DataKeys[index].Value); 

     // Write your further code 

    } 
}