在更新面板中找不到控件ID

时间:2014-02-20 10:51:25

标签: asp.net

我在网格视图中有两个文本框命名为速率和数量作为项目模板。当我更改速率和数量值时,必须更新总金额字段,但当我尝试使用更新面板时,我得到了一个错误。

这是我的代码 ASPX:

    <asp:GridView ID="gvChallan" runat="server" AutoGenerateColumns="False" 
                                     CellPadding="3" HorizontalAlign="Center" 
                                     BackColor="White" BorderColor="#CCCCCC" Font-Size="Small"
                                    BorderStyle="None" BorderWidth="1px" ShowFooter="True"  Width="950px" >
                                   <Columns>
                      <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="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>
                                        </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>

cs code:

  protected void QtyChanged(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;
    foreach (GridViewRow g1 in gvChallan.Rows)
    {
        TextBox txtgvamt = (TextBox)g1.FindControl("txtamt");
        gvamt = gvamt + float.Parse(txtgvamt.Text);
    }
    txttotamt.Text = Convert.ToString(gvamt);

}

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;
    foreach (GridViewRow g1 in gvChallan.Rows)
    {
        TextBox txtgvamt = (TextBox)g1.FindControl("txtamt");
        gvamt = gvamt + float.Parse(txtgvamt.Text);
    }
    txttotamt.Text = Convert.ToString(gvamt);


}

0 个答案:

没有答案