将数据集绑定到html表

时间:2015-01-02 12:22:34

标签: c# asp.net

在下面的代码中,我有一个数据集和html表。在我的情况下,我有25个计数的数据集,我想将它绑定到html表,但它只绑定第一行.Pls帮助我绑定所有行。

 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>   

1 个答案:

答案 0 :(得分: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];
            }