在下面的代碼中,我有文本框和下拉列表中的HTML表格,我想從datset值綁定到HTML table.But它只是綁定1行,但它有15個records.Pls幫助我這樣做。將值綁定到HTML表格
Asp.net代碼: -
public string getWhileLoopData()
{
GetProduct();
string htmlStr = "";
MastersClient objIndent = new MastersClient();
DataSet ds = objIndent.GetIndent(hidIndentID.Value);
DataRow[] drIndentID = ds.Tables[0].Select("IndentID =" + hidIndentID.Value);
for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
{
txtQty.Value = drIndentID[i]["RecommentedQuantity"].ToString();
string Qty = txtQty.Value;
string strProductID = drIndentID[i]["ProductID"].ToString();
ddlProduct.Text = strProductID;
txtDate.Text = drIndentID[i]["ProductRequiredDate"].ToString();
string date = txtDate.Text;
Response.Write(htmlStr += "<tr><td>" + Qty + "</td><td>" + strProductID + "</td><td>" + date + "</td></tr>");
}
return htmlStr;
}
HTML表格: -
<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>
這清楚地表明你的控件(txtQty,txtData,..)將被最新的行中填寫的循環和response.w禮儀不添加新行到您的HTML表格。 – Aria
@aria所以我們如何添加新行併爲其添加值? – Developer
現在看到答案,並在那裏寫下你的評論來完成。 – Aria