2017-11-20 74 views
0

중첩 된 GridView을 사용하고 있습니다. 편집을 클릭하면 아이템이 텍스트 상자에 편집을 위해 나타나지만 새 값은 행 업데이트에 반영되지 않습니다. 나는 브라우저를 통해 그것을 검사 해 보았고, 심지어는 오래된 값을 가져왔다. 새 수량 값을 구 수량 값을 보여주는 브라우저의 요소 검사 500 GridviewAsp GridView가 업데이트되지 않습니다.

inspect 스냅 샷을 보여주는 프론트 엔드 그리드의

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

행 업데이트에 대한 부분 코드는 점점

양의 이전 값

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

He 이 코드를 사용해 행을 업데이트 할 수 있습니다.

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) 보낸 사람이라고 생각한다; ** this. –