2014-03-03 48 views
1

我正在加載中繼器的數據,然後在按鈕上點擊我試圖保存數據。中繼器循環文本框文本被報告爲空

繼承人我有,但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(); 
+0

你的數據如何綁定中繼器? – Andrei

+0

我已經添加了一個編輯信息 – TMB87

+0

你有你的數據綁定包裹在'if(!IsPostBack)'? – Andrei

回答

1

在Page_load的if(!IsPostBack)條件中添加綁定Repeater控件的代碼。這對我有效。