【问题标题】:How do I get the Data from the textboxes within the gridview, nested in the repeater?如何从嵌套在中继器中的网格视图中的文本框中获取数据?
【发布时间】:2009-07-07 23:39:00
【问题描述】:

我之前尝试仅使用文本发布此内容...只有一个响应建议我更新 onblur ..这似乎不是最佳路线,因为可能有大量记录:我有以下 Gridview在转发器 ItemDataBound 事件期间构建: '>

            <asp:GridView ID="gvBeneficiary" DataKeyNames="BeneficiaryKey" OnRowCommand="gvBeneficiary_RowCommand" runat="server" AutoGenerateColumns="false">
            <Columns>


                 <asp:TemplateField HeaderText="Name">
                 <ItemTemplate>
                 <asp:HyperLink runat = "server" ID="hlEditBeneficiary" NavigateUrl='<%# "~/EditBeneficiary.aspx?bk=" + HttpUtility.UrlEncode(DataBinder.Eval(Container.DataItem, "BeneficiaryKey").ToString()) %>' Text='<%#Eval("FirstName") %>'></asp:HyperLink>  
                 </ItemTemplate>


                 </asp:TemplateField>  

                <asp:BoundField DataField="Relationship" HeaderText="Relationship" />
                <asp:TemplateField HeaderText="Shares %">

                    <ItemTemplate>
                        <asp:TextBox ID="txtEditShares" runat="server" Text='<%#Bind("Shares") %>'></asp:TextBox>
                    </ItemTemplate>
                </asp:TemplateField>

                <asp:TemplateField HeaderText="Beneficiary Type">

                <ItemTemplate>
                    <asp:DropDownList ID="ddlBeneficiaryType" runat="server" SelectedIndex='<%# GetSelectedBeneficiaryType(Eval("BeneficiaryType")) %>' DataSource='<%# BeneficiaryTypes %>' ></asp:DropDownList>

                </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField>
                <ItemTemplate>
                <asp:LinkButton  Text="Delete" CommandName='DoDelete'  CommandArgument='<%# string.Format("{0}|{1}", Eval("BeneficiaryKey"), Eval("PlanTypeKey")) %>' ID="lbDoDelete" runat="server"></asp:LinkButton>
                </ItemTemplate>

                </asp:TemplateField>          




            </Columns>

            </asp:GridView>
            <asp:HyperLink ID="hlAddBeneficiary" runat="server" Text="Add Beneficiary" NavigateUrl='<%# "~/AddEditBeneficiary.aspx?PT=" + HttpUtility.UrlEncode(DataBinder.Eval(Container.DataItem, "PlanTypeKey").ToString()) + "&CPT=" + HttpUtility.UrlEncode(DataBinder.Eval(Container.DataItem, "CorePlanType").ToString()) %>'></asp:HyperLink>

这是代码隐藏: protected void rptPlanTypes_ItemDataBound(对象发送者,RepeaterItemEventArgs e) { GridView gvBeneficiary = (GridView) e.Item.FindControl("gvBeneficiary");

        gvBeneficiary.DataSource = ((PlanType) e.Item.DataItem).BeneficiaryCollection;

        gvBeneficiary.DataBind();
    }

我有一个来自按钮的 onclick 事件,我想从中进行所有更新。任何人都知道如何深入研究行上的各个控件以一次或循环提取所有数据。 再次感谢您的所有建议。 学徒

【问题讨论】:

    标签: c# gridview .net-2.0 repeater


    【解决方案1】:

    您将需要遍历 GridView 的每一行并从您感兴趣的每个控件中收集数据。例如,下面的 sn-p 将获取每行的每个 txtEditShares 值。

    foreach (GridViewRow row in gvBeneficiary.Rows)
    {
        var txtEditShares = (TextBox)row.FindControl("txtEditShares");
        var shares = txtEditShares.Text;
        ///...
    }
    

    您需要将循环的核心内容放在一起,但这就是在 GridView 的每一行中移动并获取控制值的方式。希望对你有帮助。

    【讨论】:

      猜你喜欢
      • 2014-11-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-03-09
      相关资源
      最近更新 更多