0

I have a gridview with 6 template field,on of them is rate and quantity.when rate and quantity is changed based on that value total amount will be change.I have used ajaxtoolkit and update panel but the changes does not effect in total field.

Here is my code

ASPX

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

Every item field has some events which fires during text changed.But txttot amount doesn't change.

Code Behind

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);
}
                   
Community
  • 1
  • 1
  • Please update your code to include your question, the exact error message, and the line that the error occurs on, and if it's a compiler error or runtime error. – mason Feb 17 '14 at 19:02
  • 1
    So this is going to be tricky. You're trying to use something in a `GridView` to fire the event. Just the name of the control isn't going to do any good because each row is going to have a different name. You'll need to do something like they did in this post: http://stackoverflow.com/questions/6276544/asp-net-adding-an-updatepanel-trigger-to-a-linkbutton-inside-a-gridview. – Mike Perrenoud Feb 17 '14 at 19:03
  • i got a server error A control with ID 'txtrate' could not be found for the trigger in UpdatePanel 'uptotamt'.Here txtrate is the content template located in gridview and uptotamt is the update panel in which i put a textbox txttot which will update every text change in txtrate text box – Sandip Paul Feb 17 '14 at 19:37
  • hi all can u give me any solution of my above problem – Sandip Paul Feb 18 '14 at 14:31

0 Answers0