2017-11-20 50 views
0

入れ子のGridViewを使用しています。編集をクリックすると、項目はテキストボックスで編集用に表示されますが、新しい値は行更新に反映されません。私はブラウザを通してそれを検査しようとしましたが、それでも古い値を取得しています。Asp GridViewが更新されない

<asp:GridView ID="GVInvoiceDet" runat="server" Width="100%" AutoGenerateColumns="False" EnableViewState="False" 
      HorizontalAlign="Left" BorderStyle="Outset" OnRowCancelingEdit="GVInvoiceDet_RowCancelingEdit" 
      OnRowEditing="GVInvoiceDet_RowEditing" OnRowDataBound="GVInvoiceDet_RowDataBound" ShowFooter="True" 
      OnRowCommand="GVInvoiceDet_RowCommand" OnRowUpdating="GVInvoiceDet_RowUpdating" 
      OnRowDeleting="GVInvoiceDet_RowDeleting" OnRowDeleted="GVInvoiceDet_RowDeleted" 
      OnRowUpdated="GVInvoiceDet_RowUpdated" AllowSorting="True" DataSourceID="DSItemGrid" DataKeyNames="invoiceno,itemcd"> 
      <HeaderStyle BackColor="#0000ff" ForeColor="Yellow" /> 
      <FooterStyle BackColor="#FFFFCC" ForeColor="#330099" /> 
      <EditRowStyle BackColor="#FFFFCC" ForeColor="#330099" /> 
      <AlternatingRowStyle BackColor="#FE9CD5" /> 

      <Columns> 
       <asp:TemplateField> 
        <ItemTemplate> 
         <a href="javascript:expandcollapse('div<%# Eval("itemcd") %>', 'one');"> 
          <img id="imgdiv<%# Eval("itemcd") %>" alt="Click to show/hide Tax Details <%# Eval("itemcd") %>" border="0" src="Images/plus.png" /> 
         </a> 
        </ItemTemplate> 
        <ItemStyle HorizontalAlign="Left" Width="15px" /> 
       </asp:TemplateField> 
       <asp:TemplateField ItemStyle-Width="10%" HeaderText="Item Code" SortExpression="itemcd"> 
        <ItemTemplate> 
         <asp:Label ID="lblItemCode" runat="server" Text='<%# Eval("itemcd")%>'></asp:Label> 
        </ItemTemplate> 
        <EditItemTemplate> 
         <asp:TextBox ID="txtItemCode" Width="90%" runat="server" Text='<%# Eval("itemcd")%>' Enabled="false"></asp:TextBox> 
        </EditItemTemplate> 
        <FooterTemplate> 
         <asp:TextBox ID="txtItemCode" Width="90%" runat="server" Text='' Enabled="false"></asp:TextBox> 
        </FooterTemplate> 
       </asp:TemplateField> 
     <asp:TemplateField ItemStyle-Width="5%" HeaderText="Quantity"> 
        <ItemTemplate> 
         <asp:Label ID="lblItemQty" runat="server" Text='<%# Eval("quantity")%>'></asp:Label> 
        </ItemTemplate> 
        <EditItemTemplate> 
         <asp:TextBox ID="txtItemQty" Width="90%" runat="server" Text='<%# Bind("quantity") %>'></asp:TextBox> 
        </EditItemTemplate> 
        <FooterTemplate> 
         <asp:TextBox ID="txtItemQty" Width="90%" MaxLength="100" runat="server"></asp:TextBox> 
        </FooterTemplate> 
       </asp:TemplateField> 
     <asp:CommandField ShowEditButton="True" HeaderText="Edit" /> 
       <asp:TemplateField HeaderText="Delete" ItemStyle-Width="5%"> 
        <ItemTemplate> 
         <asp:LinkButton ID="linkDeleteInvoiceItem" CommandName="DeleteItem" runat="server">Delete</asp:LinkButton> 
        </ItemTemplate> 
        <FooterTemplate> 
         <asp:LinkButton ID="linkAddInvoiceItem" CommandName="AddItem" runat="server">Add</asp:LinkButton> 
        </FooterTemplate> 
       </asp:TemplateField> 
     </Columns> 
     </asp:GridView> 
     <asp:SqlDataSource ID="DSItemGrid" runat="server" ConnectionString="<%$ ConnectionStrings:GSTCS %>" ProviderName="<%$ ConnectionStrings:GSTCS.ProviderName %>" 
      SelectCommand="select invoiceno, dt.itemcd itemcd, mast.itemdesc itemdesc, mast.hsncd hsncd, dt.quantity quantity, 
      mast.unitrate unitrate, dt.unitvalue unitvalue, mast.itempercentage itempercentage 
      from GSTINVOICEDT dt join GSTITEMMASTER mast on (dt.itemcd = mast.itemcd and dt.unitcode = mast.unitcode and dt.projectcode = mast.projectcode) 
      where dt.unitcode = :unitCode and dt.projectCode = :projCode and dt.invoiceno = :invoiceNo order by invoiceno, itemcd" 
      UpdateCommand="UPDATE GSTINVOICEDT set quantity = :quantity ,unitRate =:unitRate, unitValue=:unitValue 
          WHERE invoiceno = :invoiceno and unitcode= :unitcode and projectcode = :projectcode 
          and itemcd = :itemcd" 
      OnUpdating="DSItemGrid_Updating"> 
      <SelectParameters> 
       <asp:SessionParameter DefaultValue="05" Name="unitCode" SessionField="unit" /> 
       <asp:SessionParameter DefaultValue="0501" Name="projCode" SessionField="project" /> 
       <asp:SessionParameter DefaultValue="INVOICENO" Name="invoiceNo" SessionField="invoiceNo" Type="String" /> 
      </SelectParameters> 
      <UpdateParameters> 
       <asp:Parameter Name="itemcd" Type="String" /> 
       <asp:Parameter Name="quantity" Type="Int32" /> 
       <asp:Parameter Name="unitRate" Type="Decimal" /> 
       <asp:Parameter Name="unitValue" Type="Decimal" /> 
       <asp:Parameter Name="invoiceno" Type="String" /> 
       <asp:SessionParameter Name="unitcode" SessionField="unit" /> 
       <asp:SessionParameter Name="projectcode" SessionField="project" />     
      </UpdateParameters> 
     </asp:SqlDataSource> 

    </div> 

新しい数量値に行更新のための50

部分コードもなっている古い数量値を示すブラウザの検査要素の500 Gridview

inspect スナップショットを示すフロントエンドグリッドのスナップショット数量のための古い値

protected void GVInvoiceDet_RowUpdating(object sender, GridViewUpdateEventArgs e) 
     { 
      GridView temp = (GridView)sender; 
      //Get the values stored in the text boxes 
      string itemCode = ((TextBox)temp.Rows[e.RowIndex].FindControl("txtItemCode")).Text; 
      string quantity = ((TextBox)temp.Rows[e.RowIndex].FindControl("txtItemQty")).Text; 
      string unitRate = ((TextBox)temp.Rows[e.RowIndex].FindControl("txtItemUnitRate")).Text; 
      string unitValue = ((TextBox)temp.Rows[e.RowIndex].FindControl("txtItemUnitValue")).Text;  
      string unit = Session["unit"].ToString(); 
      string proj = Session["project"].ToString(); 
+0

データベーステーブルが更新されているかどうかを確認しますか? –

+0

@ M.Y.Mnuデータベーステーブルの更新がありません。それで私はデバッグを試みました。 –

+0

次に、テーブルの値を最初に更新しない理由をチェックする必要があります。 –

答えて

0

彼あなたはこのコードを行を更新するために試すことができます

protected void GVInvoiceDet_RowUpdating(object sender, GridViewRowEventArgs e) 
{ 
    string itemCode= (TextBox)GVInvoiceDet.Rows[e.RowIndex].FindControl("txtItemCode")).Text; 
    string quantity = (TextBox)GVInvoiceDet.Rows[e.RowIndex].FindControl("txtItemQty")).Text; 
    string unitRate = ((TextBox)GVInvoiceDet.Rows[e.RowIndex].FindControl("txtItemUnitRate")).Text; 
    string unitValue = ((TextBox)GVInvoiceDet.Rows[e.RowIndex].FindControl("txtItemUnitValue")).Text;  
    string unit = Session["unit"].ToString(); 
    string proj = Session["project"].ToString(); 
    GVInvoiceDet.EditIndex = -1; 
    // call bind grid method here 
} 
+0

作業データが更新されました。しかし、私は自分のコードで何が間違っていたかを論理的には知りませんでした –

+0

あなたは** GridView temp =(GridView)sender; **を使っていると思います。 –

関連する問題