我有一个带有6个模板字段的gridview,其中是速率和数量。当根据该值更改速率和数量时,总量将会发生变化。我使用了ajaxtoolkit和更新面板,但更改不起作用总场。
这是我的代码
<tr>
<td colspan="5">
<asp:GridView ID="gvOrder" runat="server" AutoGenerateColumns="False"
CellPadding="3" HorizontalAlign="Center" OnRowCreated="gvOrder_RowCreated"
BackColor="White" BorderColor="#CCCCCC" Font-Size="Small"
BorderStyle="None" BorderWidth="1px" ShowFooter="True" Width="950px" >
<Columns>
<asp:TemplateField HeaderText="Product Name">
<ItemTemplate>
<asp:DropDownList ID="drpproduct" Width="200px" runat="server" DataValueField="PName"
onselectedindexchanged="drpproduct_SelectedIndexChanged" AutoPostBack="true" >
</asp:DropDownList>
</ItemTemplate>
<HeaderStyle Width="200px" />
</asp:TemplateField>
<asp:TemplateField HeaderText="Sub Item">
<ItemTemplate>
<asp:UpdatePanel ID="Upsubitem" runat="server" UpdateMode="Conditional" RenderMode="Inline">
<Triggers>
<asp:AsyncPostBackTrigger ControlID="drpproduct" EventName="TextChanged" />
</Triggers>
<ContentTemplate>
<asp:DropDownList ID="drpsubitem" Width="200px" runat="server" DataValueField="BName"
onselectedindexchanged="drpsubitem_SelectedIndexChanged" AutoPostBack="true" >
</asp:DropDownList>
</ContentTemplate>
</asp:UpdatePanel>
</ItemTemplate>
<HeaderStyle Width="200px" />
</asp:TemplateField>
<asp:TemplateField HeaderText="Quantity">
<ItemTemplate>
<asp:UpdatePanel ID="upqty" runat="server" UpdateMode="Conditional" RenderMode="Inline">
<Triggers>
<asp:AsyncPostBackTrigger ControlID="drpproduct" EventName="TextChanged" />
</Triggers>
<ContentTemplate>
<asp:TextBox ID="txtquantity" runat="server" MaxLength="5" CssClass="textb" Width="70px" OnTextChanged="QtyChanged" AutoPostBack="true" ></asp:TextBox>
</ContentTemplate>
</asp:UpdatePanel>
</ItemTemplate>
<HeaderStyle Width="70px" />
</asp:TemplateField>
<asp:TemplateField HeaderText="Unit">
<ItemTemplate>
<asp:UpdatePanel ID="upUnit" runat="server" UpdateMode="Conditional" RenderMode="Inline">
<Triggers>
<asp:AsyncPostBackTrigger ControlID="drpproduct" EventName="TextChanged" />
</Triggers>
<ContentTemplate>
<asp:TextBox ID="txtunit" runat="server" CssClass="textb" Width="60px" Enabled="false" ></asp:TextBox>
</ContentTemplate>
</asp:UpdatePanel>
</ItemTemplate>
<HeaderStyle Width="60px" />
</asp:TemplateField>
<asp:TemplateField HeaderText="Rate">
<ItemTemplate>
<asp:UpdatePanel ID="UpRate" runat="server" UpdateMode="Conditional" RenderMode="Inline">
<Triggers>
<asp:AsyncPostBackTrigger ControlID="drpsubitem" EventName="TextChanged" />
<asp:AsyncPostBackTrigger ControlID="drpproduct" EventName="TextChanged" />
</Triggers>
<ContentTemplate>
<asp:TextBox ID="txtrate" runat="server" CssClass="textb" Width="70px" MaxLength="5" OnTextChanged="RateChanged" AutoPostBack="true" ></asp:TextBox>
</ContentTemplate>
</asp:UpdatePanel>
</ItemTemplate>
<HeaderStyle Width="70px" />
</asp:TemplateField>
<asp:TemplateField HeaderText="Amount">
<ItemTemplate>
<asp:UpdatePanel ID="UpAmount" runat="server" UpdateMode="Conditional" RenderMode="Inline">
<Triggers>
<asp:AsyncPostBackTrigger ControlID="drpproduct" EventName="TextChanged" />
<asp:AsyncPostBackTrigger ControlID="drpsubitem" EventName="TextChanged" />
<asp:AsyncPostBackTrigger ControlID="txtrate" EventName="TextChanged" />
<asp:AsyncPostBackTrigger ControlID="txtquantity" EventName="TextChanged" />
</Triggers>
<ContentTemplate>
<asp:TextBox ID="txtamt" runat="server" OnTextChanged="AmtChanged" AutoPostBack="true" CssClass="textb" Width="80px" MaxLength="20" ></asp:TextBox>
</ContentTemplate>
</asp:UpdatePanel>
</ItemTemplate>
<FooterStyle HorizontalAlign="Center" />
<FooterTemplate>
<asp:Button ID="ButtonAdd" runat="server"
Text="Add New Row" onclick="ButtonAdd_Click"
Width="100" />
</FooterTemplate>
<HeaderStyle Width="80px" />
</asp:TemplateField>
<asp:TemplateField HeaderText="PCode">
<ItemTemplate>
<asp:UpdatePanel ID="UpProductCode" runat="server" UpdateMode="Conditional" RenderMode="Inline">
<Triggers>
<asp:AsyncPostBackTrigger ControlID="drpproduct" EventName="TextChanged" />
</Triggers>
<ContentTemplate>
<asp:Label ID="lblpcode" runat="server" Text="" Width="10px" Enabled="false"></asp:Label>
</ContentTemplate>
</asp:UpdatePanel>
</ItemTemplate>
<HeaderStyle Width="10px" />
</asp:TemplateField>
<asp:TemplateField HeaderText="SCode">
<ItemTemplate>
<asp:UpdatePanel ID="UpSubitemCode" runat="server" UpdateMode="Conditional" RenderMode="Inline">
<Triggers>
<asp:AsyncPostBackTrigger ControlID="drpproduct" EventName="TextChanged" />
<asp:AsyncPostBackTrigger ControlID="drpsubitem" EventName="TextChanged" />
</Triggers>
<ContentTemplate>
<asp:Label ID="lblscode" runat="server" Text="" Width="10px" Enabled="false"></asp:Label>
</ContentTemplate>
</asp:UpdatePanel>
</ItemTemplate>
<HeaderStyle Width="10px" />
</asp:TemplateField>
</Columns>
<FooterStyle BackColor="White" ForeColor="#000066" />
<HeaderStyle BackColor="#006699" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="White" ForeColor="#000066" HorizontalAlign="Left" />
<RowStyle ForeColor="#000066" />
<SelectedRowStyle BackColor="#669999" Font-Bold="True" ForeColor="White" />
<SortedAscendingCellStyle BackColor="#F1F1F1" />
<SortedAscendingHeaderStyle BackColor="#007DBB" />
<SortedDescendingCellStyle BackColor="#CAC9C9" />
<SortedDescendingHeaderStyle BackColor="#00547E" />
</asp:GridView>
</td>
</tr>
<tr>
<td style="width:15%;">
<asp:Label ID="Label8" runat="server" CssClass="tranlbl" Text="Total Qunatity :"></asp:Label>
</td>
<td style="width:25%;">
<asp:TextBox ID="txttotqty" runat="server" CssClass="texttot" Width="180px"
Enabled="False" ></asp:TextBox>
</td>
<td style="width:20%;">
</td>
<td style="width:15%;">
<asp:Label ID="Label9" runat="server" CssClass="tranlbl" Text="Total Amount :"></asp:Label>
</td>
<td style="width:25%;">
<asp:UpdatePanel ID="uptotamt" runat="server" UpdateMode="Conditional" RenderMode="Inline">
<Triggers>
<asp:AsyncPostBackTrigger ControlID="txtrate" EventName="TextChanged" />
</Triggers>
<ContentTemplate>
<asp:TextBox ID="txttot" runat="server" CssClass="texttot" Width="180px"
Enabled="False" ></asp:TextBox>
</ContentTemplate>
</asp:UpdatePanel>
</td>
</tr>
每个项目字段都有一些在文本更改期间触发的事件。但是txttot数量不会改变。
protected void RateChanged(object sender, EventArgs e)
{
GridViewRow row = (GridViewRow)drpsubitem.NamingContainer;
TextBox prate = (TextBox)row.FindControl("txtrate");
TextBox pqty = (TextBox)row.FindControl("txtquantity");
TextBox pamt = (TextBox)row.FindControl("txtamt");
pamt.Text = Convert.ToString(float.Parse(prate.Text) * Convert.ToInt32(pqty.Text));
float gvamt = 0;
int gqty = 0;
foreach (GridViewRow g1 in gvOrder.Rows)
{
gvamt = gvamt + float.Parse(pamt.Text);
gqty = gqty + Convert.ToInt32(pqty.Text);
}
txttot.Text = Convert.ToString(gvamt);
txttotqty.Text = Convert.ToString(gqty);
}