本文介绍了无法获取GridViewRow的ParentIndex的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

无法获得ParentIndex :(



当我从第3行更改文本时,它总是给出0值



Unable to get ParentIndex :(

All the time it gives 0 value while I am Changing Text from Row 3

public void txtChildQty_textChanged(object sender, EventArgs e)
{
    IsChildGridAdded = true;
    decimal QTY;
    int Parentindex;

    GridViewRow dgvChildDocuments = (GridViewRow)((TextBox)sender).Parent.Parent;
    Parentindex = dgvChildDocuments.RowIndex;

    decimal UnitPerPrice = Convert.ToDecimal(dgvChildDocuments.Cells[1].Text.Substring(1).ToString());
    TextBox t = (TextBox)dgvChildDocuments.FindControl("txtChildQty");
    if (t.Text == "")
    { QTY = 1; t.Text = "1"; }
    else
    {
        try { QTY = Convert.ToDecimal(t.Text); }
        catch { QTY = 0; t.Text = "1"; }
    }

    dgvChildDocuments.Cells[3].Text = "$" + (UnitPerPrice * QTY).ToString();

    ChildQty = TotalChildQty(Parentindex);
    
    BindTotalAmount();
}




<asp:GridView runat="server" ID="dgvCartItems" AutoGenerateColumns="false" 

      CssClass="AccountBillinggrid" Visible="true"

      onrowcommand="dgvCartItems_RowCommand" 

      onrowdeleting="dgvCartItems_RowDeleting" 

        onrowdatabound="dgvCartItems_RowDataBound">
      <EmptyDataTemplate>
        <center><b style="color:Red">No Items In Shopping Cart</b></center>
      </EmptyDataTemplate>
      <Columns>
        <asp:BoundField HeaderText="Order ProductID" DataField="CartOrderProductID"/>
        <asp:TemplateField HeaderText="Item" >
          <ItemTemplate>
            <asp:Label runat="server" ID="lblproductTitleDisplay" Visible="false"></asp:Label>
            <asp:ImageButton CommandName="ColExp" CommandArgument='<%# Container.DataItemIndex %>' runat="server" ID="productCaseGroupIcon" ImageUrl="/images/icons/inline/expand.jpg" Visible="false" OnClick="productCaseGroupIcon_Click" style="width:auto" />
            <h1>
              <asp:Label runat="server" ID="lblCaseNumber" Visible="false"></asp:Label>
              <asp:ImageButton CommandName="NavigateToSummary" CommandArgument='<%# Container.DataItemIndex %>' runat="server" ID="ImgSummaryDetails" ImageUrl="/images/icons/inline/view.png" Visible="false" style="width:auto"  />
            </h1>
            <br />
            <font style="font-size:10px;">
              &nbsp;&nbsp;&nbsp;
              <em>
                
                <asp:Label runat="server" ID="lblPlaintiffandDefendant" Visible="false"></asp:Label>
              
              </em>
              
            </font>
            <br />&nbsp;&nbsp;&nbsp;
            <font style="font-size:10px;">
              <asp:Label runat="server" ID="lblClientCode" Visible="false" Text="Client Code/Notes:"></asp:Label>
            </font>
            <asp:TextBox runat="server" ID="txtNotesGroup" Visible="false" style="font-size:10px"></asp:TextBox>

           
            <asp:GridView runat="server" ID="dgvChildDocuments" AutoGenerateColumns="false" Visible="false" CssClass="AccountBillinggrid">
            <Columns>
            <asp:TemplateField>
            <ItemTemplate>
            <asp:ImageButton runat="server" ID="pdfDocumentsIcon" ImageUrl="/images/icons/inline/pdf.gif" />
            <font style="font-size:12px;"><asp:Label runat="server" ID="lblPDFDocuments"></asp:Label></font>
            </ItemTemplate>
            </asp:TemplateField>

            <asp:BoundField DataField="productOrderPrice" DataFormatString="${0}" />

            <asp:TemplateField>
          <ItemTemplate>
            <asp:TextBox runat="server" ID="txtChildQty" AutoPostBack="true" Text='<%# Eval("productQTY") %>' OnTextChanged="txtChildQty_textChanged"></asp:TextBox>
            <asp:ImageButton CommandName="DeleteChildItem" CommandArgument='<%# Container.DataItemIndex %>' runat="server" ID="imgChildDelete" ImageUrl="/images/icons/inline/cross.png" OnClick="imgChildDelete_Click" style="vertical-align:middle;" />
          </ItemTemplate>
        </asp:TemplateField>

        <asp:BoundField DataField="productOrderPrice" DataFormatString="${0}"/>

        <asp:TemplateField>
        <ItemTemplate>
        <asp:HiddenField runat="server" ID="hdnCaseDocumentID"/>
        </ItemTemplate>
        </asp:TemplateField>
            </Columns>
            </asp:GridView>

         
        </ItemTemplate>
        </asp:TemplateField>
        <asp:BoundField HeaderText="Unit Price" DataField="productOrderPrice" DataFormatString="${0}" />
        <asp:TemplateField HeaderText="Qty" ControlStyle-Width="30">
          <ItemTemplate>
            <asp:TextBox runat="server" ID="txtQty" AutoPostBack="true" OnTextChanged="txtQty_textChanged" Width="25px" Visible="false"></asp:TextBox>
            <asp:ImageButton CommandName="Delete" CommandArgument='<%# Container.DataItemIndex %>' runat="server" ID="imgDelete" ImageUrl="/images/icons/inline/cross.png" Visible="false" style="vertical-align:middle; width:13px;" />
          </ItemTemplate>
        </asp:TemplateField>
        <asp:BoundField HeaderText="Total" />
      </Columns>
    </asp:GridView>

推荐答案




<asp:GridView runat="server" ID="dgvCartItems" AutoGenerateColumns="false" 

      CssClass="AccountBillinggrid" Visible="true"

      onrowcommand="dgvCartItems_RowCommand" 

      onrowdeleting="dgvCartItems_RowDeleting" 

        onrowdatabound="dgvCartItems_RowDataBound">
      <EmptyDataTemplate>
        <center><b style="color:Red">No Items In Shopping Cart</b></center>
      </EmptyDataTemplate>
      <Columns>
        <asp:BoundField HeaderText="Order ProductID" DataField="CartOrderProductID"/>
        <asp:TemplateField HeaderText="Item" >
          <ItemTemplate>
            <asp:Label runat="server" ID="lblproductTitleDisplay" Visible="false"></asp:Label>
            <asp:ImageButton CommandName="ColExp" CommandArgument='<%# Container.DataItemIndex %>' runat="server" ID="productCaseGroupIcon" ImageUrl="/images/icons/inline/expand.jpg" Visible="false" OnClick="productCaseGroupIcon_Click" style="width:auto" />
            <h1>
              <asp:Label runat="server" ID="lblCaseNumber" Visible="false"></asp:Label>
              <asp:ImageButton CommandName="NavigateToSummary" CommandArgument='<%# Container.DataItemIndex %>' runat="server" ID="ImgSummaryDetails" ImageUrl="/images/icons/inline/view.png" Visible="false" style="width:auto"  />
            </h1>
            <br />
            <font style="font-size:10px;">
              &nbsp;&nbsp;&nbsp;
              <em>
                
                <asp:Label runat="server" ID="lblPlaintiffandDefendant" Visible="false"></asp:Label>
              
              </em>
              
            </font>
            <br />&nbsp;&nbsp;&nbsp;
            <font style="font-size:10px;">
              <asp:Label runat="server" ID="lblClientCode" Visible="false" Text="Client Code/Notes:"></asp:Label>
            </font>
            <asp:TextBox runat="server" ID="txtNotesGroup" Visible="false" style="font-size:10px"></asp:TextBox>

           
            <asp:GridView runat="server" ID="dgvChildDocuments" AutoGenerateColumns="false" Visible="false" CssClass="AccountBillinggrid">
            <Columns>
            <asp:TemplateField>
            <ItemTemplate>
            <asp:ImageButton runat="server" ID="pdfDocumentsIcon" ImageUrl="/images/icons/inline/pdf.gif" />
            <font style="font-size:12px;"><asp:Label runat="server" ID="lblPDFDocuments"></asp:Label></font>
            </ItemTemplate>
            </asp:TemplateField>

            <asp:BoundField DataField="productOrderPrice" DataFormatString="




这篇关于无法获取GridViewRow的ParentIndex的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-01 14:00