我正在使用嵌套的GridView
。单击编辑时,项目将显示在texbox中进行编辑,但新值不会反映在rowupdating中。我尝试通过浏览器进行检查,即便如此,它也会获取旧值。
<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>
行更新的部分代码也是数量
的旧值 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)
在这里,您可以尝试使用此代码更新行
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
}