.aspx
<tr bgcolor="white">
<td style="height: 40px;" colspan="2">
<asp:TextBox ID="txtSmallCategory1" runat="server" Width="100"></asp:TextBox> <asp:TextBox ID="txtUnit1" runat="server" Width="50"></asp:TextBox>
<asp:TextBox ID="txtNum1" runat="server" Width="50"></asp:TextBox> <asp:TextBox ID="txtPrice1" runat="server" Width="80"></asp:TextBox>
<asp:TextBox ID="txtRemarks1" runat="server" Width="350px"></asp:TextBox>
</td>
</tr>
<tr bgcolor="white">
<td style="height: 40px;" colspan="2">
<asp:TextBox ID="txtSmallCategory2" runat="server" Width="100"></asp:TextBox> <asp:TextBox ID="txtUnit2" runat="server" Width="50"></asp:TextBox>
<asp:TextBox ID="txtNum2" runat="server" Width="50"></asp:TextBox> <asp:TextBox ID="txtPrice2" runat="server" Width="80"></asp:TextBox>
<asp:TextBox ID="txtRemarks2" runat="server" Width="350px"></asp:TextBox>
</td>
</tr>
<tr bgcolor="white">
<td style="height: 40px;" colspan="2">
<asp:TextBox ID="txtSmallCategory3" runat="server" Width="100"></asp:TextBox> <asp:TextBox ID="txtUnit3" runat="server" Width="50"></asp:TextBox>
<asp:TextBox ID="txtNum3" runat="server" Width="50"></asp:TextBox> <asp:TextBox ID="txtPrice3" runat="server" Width="80"></asp:TextBox>
<asp:TextBox ID="txtRemarks3" runat="server" Width="350px"></asp:TextBox>
</td>
</tr>
<tr bgcolor="white">
<td style="height: 40px;" colspan="2">
<asp:TextBox ID="txtSmallCategory4" runat="server" Width="100"></asp:TextBox> <asp:TextBox ID="txtUnit4" runat="server" Width="50"></asp:TextBox>
<asp:TextBox ID="txtNum4" runat="server" Width="50"></asp:TextBox> <asp:TextBox ID="txtPrice4" runat="server" Width="80"></asp:TextBox>
<asp:TextBox ID="txtRemarks4" runat="server" Width="350px"></asp:TextBox>
</td>
</tr>
<tr bgcolor="white">
<td style="height: 40px;" colspan="2">
<asp:TextBox ID="txtSmallCategory5" runat="server" Width="100"></asp:TextBox> <asp:TextBox ID="txtUnit5" runat="server" Width="50"></asp:TextBox>
<asp:TextBox ID="txtNum5" runat="server" Width="50"></asp:TextBox> <asp:TextBox ID="txtPrice5" runat="server" Width="80"></asp:TextBox>
<asp:TextBox ID="txtRemarks5" runat="server" Width="350px"></asp:TextBox>
</td>
</tr>
.aspx.cs内容
ProjectPrice proPrice = new ProjectPrice();
for (int i = 1; i <= 5; i++)
{
if (!string.IsNullOrEmpty(((TextBox)Page.FindControl(string.Format("txtSmallCategory{0}", i))).Text))
{
proPrice.ProjectId = proId;
proPrice.ProjectBigCate = this.ddlBigCategory.SelectedValue;
proPrice.ProjectSmallCate = ((TextBox)Page.FindControl(string.Format("txtSmallCategory{0}", i))).Text;
proPrice.Unit = ((TextBox)Page.FindControl(string.Format("txtUnit{0}", i))).Text;
proPrice.Num = ((TextBox)Page.FindControl(string.Format("txtNum{0}", i))).Text == "" ? 0 : Convert.ToInt32(((TextBox)Page.FindControl(string.Format("txtNum{0}", i))).Text);
proPrice.ProjectCountPrice = ((TextBox)Page.FindControl(string.Format("txtPrice{0}", i))).Text == "" ? 0 : Convert.ToDecimal(((TextBox)Page.FindControl(string.Format("txtPrice{0}", i))).Text);
proPrice.InsertTime = DateTime.Now;
proPrice.Remarks = ((TextBox)Page.FindControl(string.Format("txtRemarks{0}", i))).Text;
ServiceLocator.ProjectService.InsertProjectPrice(proPrice);
}
}
====================================================
需要注意的2点:
1。页面取值可以使用page.FindControl("控件的ID号")
2。string.Format("home.aspx?ID={0}",NumId);用法。
Response.Redirect(string.Format("documentlist.aspx?id={0}&page={1}&word={2}&dept={3}", cateId, AspNetPager_Doc.CurrentPageIndex, HttpUtility.UrlEncode(keyWord), txtDept.Value));