转发器循环文本框文本报告为空

时间:2014-03-03 13:38:13

标签: c# repeater

我正在加载带有数据的转发器,然后点击按钮我试图保存数据。

继续我所拥有的,但tbDate.text或tbAmount.texts总是被报告为“”而不是值。

 <asp:Repeater runat="server" ID="rptInstallments" OnItemDataBound="rptInstallments_ItemDataBound">
                        <ItemTemplate>
                              <div class="form-group">
                                <label class="control-label">Installment Amount</label>
                                <div class="controls">
                                    <asp:TextBox runat="server" ID="txtAmount" CssClass="form-control"></asp:TextBox>
                                </div>
                            </div>
                             <div class="form-group">
                                <label class="control-label">Installment Date</label>
                                <div class="controls">
                                    <asp:TextBox runat="server" ID="txtDate" CssClass="form-control datepicker"></asp:TextBox>
                                </div>
                            </div>
                        </ItemTemplate>
                    </asp:Repeater>

后面的代码:

protected void btGo_Click(object sender, EventArgs e)
        {
            foreach (RepeaterItem item in rptInstallments.Items)
            {
                TextBox tbDate = item.FindControl("txtDate") as TextBox;
                TextBox tbAmount = item.FindControl("txtAmount") as TextBox;
                String myAmount = tbAmount.Text;
                String myDate = tbDate.Text;

                var rInstall = dtInstall.NewSubPIDInstallmentsRow();
                rInstall.SPID = SPID;
                rInstall.InstallmentAmount = Convert.ToDecimal(myAmount);
                rInstall.InstallmentDue = Convert.ToDateTime(myDate);

                dtInstall.AddSubPIDInstallmentsRow(rInstall);
                taInstall.Update(dtInstall);

            }

        }

修改

我正在攻击转发器,没有真正的数据源。这可能是问题吗?

int[] RowCount = new int[numberOfInstallments];

                rptInstallments.DataSource = RowCount;
                rptInstallments.DataBind();

1 个答案:

答案 0 :(得分:1)

在Page_load的if(!IsPostBack)条件中添加使用Repeater控件绑定的代码。这对我有用。