2015-01-02 73 views
-1

在下面的代碼中,我有一個數據集和html表。在我的情況下,我有25個數的數據集,我想綁定到html表,但它只綁定第一行.Pls幫助我綁定所有行。將數據集綁定到html表

MastersClient objIndent = new MastersClient(); 
       DataSet ds = objIndent.GetIndent(hidIndentID.Value); 

       DataRow[] drIndentID = ds.Tables[0].Select("IndentID =" + hidIndentID.Value); 
if (drIndentID.Length > 0) 
       { 
//Count is 25 
for (int i = 0; i < ds.Tables[0].Rows.Count; i++) 
         { 
          txtQty.Value = drIndentID[i]["RecommentedQuantity"].ToString(); 
          string strProductID = drIndentID[i]["ProductID"].ToString(); 
          ddlProduct.Text = strProductID; 
          txtDate.Text = drIndentID[i]["ProductRequiredDate"].ToString(); 
         } 

} 





<table id="dataTable" width="350px" border="1" runat="server"> 
     <tr> 
      <td><input id="checkbox" type="checkbox" name="chk" runat="server"/></td> 
      <td><input type="text" name="txt" id="txtQty" runat="server"/></td> 
      <td> 
      <asp:DropDownList ID="ddlProduct" runat="server" Style="width: 100%; height:23px" ></asp:DropDownList> 

      </td> 
      <td> 
      <asp:TextBox ID="txtDate" Style="text-align: left" onkeypress="return isNumberKey(event, false);" 
                 onblur="DateValidation(this)" onkeyup="ValidateDate(this, event.keyCode)" onkeydown="return DateFormat(this, event.keyCode)" 
                 Height="20px" runat="server" Width="80px"> </asp:TextBox> 


      </td> 
     </tr> 
    </table> 
+0

您可以使用中繼器來重複你的錶行,你沒有這樣做,這就是爲什麼你看到的只是一個單一 –

+0

參考:http://stackoverflow.com/questions/9361729/create-a-html-table-with-an-asp-repeater-repeating-horizo​​ntally –

回答

0

你的aspx

<asp:Repeater ID="rptCategories" runat="server"> 
    <HeaderTemplate> 
     <table id="dataTable" width="350px" border="1"> 
    </HeaderTemplate> 
    <ItemTemplate> 
     <tr> 
      <td><input id="checkbox" type="checkbox" name="chk" runat="server"/></td> 
      <td><input type="text" name="txt" id="txtQty" runat="server"/></td> 
      <td> 
      <asp:DropDownList ID="ddlProduct" runat="server" Style="width: 100%; height:23px" >    </asp:DropDownList> 

      </td> 
      <td> 
      <asp:TextBox ID="txtDate" Style="text-align: left" onkeypress="return isNumberKey(event, false);" onblur="DateValidation(this)" onkeyup="ValidateDate(this, event.keyCode)" onkeydown="return DateFormat(this, event.keyCode)" Height="20px" runat="server" Width="80px"> </asp:TextBox> 


      </td> 
     </tr> 
    </ItemTemplate> 
    <FooterTemplate> 
     </table> 
    </FooterTemplate> 
</asp:Repeater> 

和代碼背後

  MastersClient objIndent = new MastersClient(); 
      DataSet ds = objIndent.GetIndent(hidIndentID.Value); 

      DataRow[] drIndentID = ds.Tables[0].Select("IndentID =" + hidIndentID.Value); 
      if (drIndentID.Length > 0) 
      { 
       rptCategories.DataSource=ds.Tables[0]; 
      } 
+0

它引發錯誤ddlProduct不存在 – Developer

+0

關於whi ch line ?. –

+0

我有一個綁定下拉列表的方法ddlProduct.DataSource = dsProduct.Tables [1]; ddlProduct.DataTextField =「ProductName」; ddlProduct.DataValueField =「ProductID」; ddlProduct.DataBind(); – Developer