MissCoder87
MissCoder87

Reputation: 2669

Repeater loop textbox text is being reported as empty

I'm loading a repeater with data and then on a button click i'm trying to save the data.

Heres what I have but the tbDate.text or tbAmount.texts are always being reported back as "" instead of the values.

 <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>

Heres the backend code:

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);

            }

        }

EDIT

I'm hacking in the repeater to no real data source. Could this be the problem?

int[] RowCount = new int[numberOfInstallments];

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

Upvotes: 1

Views: 700

Answers (1)

Sushil Kumar
Sushil Kumar

Reputation: 11

Add your code of Binding the Repeater control with in the if (!IsPostBack) condition of Page_load. This worked for me.

Upvotes: 1

Related Questions