繁体   English   中英

从嵌套的gridview获取textbox.text

[英]Get textbox.text from nested gridview

我有一个父GridView和一个子GridView

<!-- Parent -->
<asp:GridView ID="gvParent" runat="server" AutoGenerateColumns="false" Width="100%"  CssClass="Grid"
    DataKeyNames="SupplierReference" OnRowDataBound="gvParent_OnRowDataBound" >
    <Columns>
        <asp:TemplateField>
            <ItemTemplate>

                    <img alt = "" style="cursor: pointer" src="images/plus.png" />
                    <asp:Panel ID="pnlOrders" runat="server" Style="display: none">

                            <!-- Child -->
                            <asp:GridView ID="gvChild"  runat="server" AutoGenerateColumns="false" CssClass = "ChildGrid" 
                            ShowFooter = "true" OnRowDataBound="gvChild_OnRowDataBound">
                            <Columns>
                                <asp:TemplateField HeaderText="Qty"  ItemStyle-Width="100px">
                                        <ItemTemplate>                  
                                                <asp:TextBox ID="TextBox1" runat="server" Text='<%#Eval("Qty")%>' />                                
                                        </ItemTemplate>
                                </asp:TemplateField >     
                            </Columns>
                        </asp:GridView>

                    </asp:Panel>
            </ItemTemplate>
        </asp:TemplateField>

        <asp:TemplateField>
            <ItemTemplate>
                <asp:LinkButton ID="lnkSelectQtys" runat="server"
                    CommandArgument = '<%# Eval("SupplierReference")%>' CommandName="SelectQtys"
                    OnClientClick = "return confirm('Add these materials to this task?')"
                    Text = "Add" OnClick="getQty"  ></asp:LinkButton>

            </ItemTemplate>
        </asp:TemplateField>
    </Columns>
</asp:GridView>

我正在尝试创建一个文本框,用户可以更改该值,当他们单击添加时,我希望能够将该文本拖入C#代码中并使用它。 我无法将其纳入我的C#代码中。

    protected void getQty(object sender, EventArgs e)
    {
        //After clicking "add"....
        //Do something here to get text from each TextBox1 in the Child gridview


    }

在我遗下剩下的小头发之前,请有人帮助...

protected void getQty(object sender, EventArgs e)
{
    //After clicking "add"....
    string s;
    for(i=0; i < gvChild.Rows.Count; i++)
    {
        s = ((TextBox)gvChild.Rows[i].FindControl("TextBox1")).Text; 
    }
    //Do what you want to with this string

}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM