下面是我的网站的一部分,其中数据是由后面的代码中的SQL查询加载的,下面列出了...我的问题是如何复制第二个< <中的> table> 如果在查询后面的代码中返回了多条记录...任何指针或提示都表示赞赏......
- .aspx表 `
<h2>Rebate Measures</h2>
<asp:Textbox ID="ProjectID" runat="server"></asp:Textbox>
<table border="1">
<tr style="background-color: beige">
<th>Delete</th>
<th>Packet #</th>
<th>EEC Ref #</th>
<th class="auto-style1">PTR Ref #</th>
<th>Residential Measure</th>
<th>PTCS</th>
<th>PTCS Ducts</th>
<th>PTCS Comm</th>
<th>Bus Bar KWh</th>
<th>Saved KWh</th>
<th>Msr Life</th>
<th>BPA Credit Rate</th>
<th>BPAtoFPUD Reimburse</th>
<th># of Units</th>
<th>Unit Type</th>
<th>Funding Source</th>
<th>Bid Cost</th>
<th>Customer Rebate</th>
</tr>
<tr style="background-color:#E0E0E0">
<td>
<asp:ImageButton Style="float:none; width: 20px; padding: 0; display: inline" ToolTip="Delete" OnClick="Delete_Click" ID="ImageButton1" ImageUrl="Images/DeletePage.gif" runat="server"></asp:ImageButton>
</td>
<td>
<asp:DropDownList ID="DropDownList1" CssClass="ddl" Width="60px" OnTextChanged="PacketNum_TextChanged" AutoPostBack="true" runat="server"></asp:DropDownList>
</td>
<td>
<asp:DropDownList CssClass="ddl" ID="DropDownList2" Width="115px" OnTextChanged="EECNum_TextChanged" AutoPostBack="true" runat="server"></asp:DropDownList>
</td>
<td class="auto-style1">
<asp:TextBox ID="TextBox1" Width="100px" runat="server"></asp:TextBox>
</td>
<td>
<asp:TextBox ID="TextBox2" Width="350px" runat="server" Wrap="true" ></asp:TextBox>
</td>
<td>
<asp:TextBox ID="TextBox3" MaxLength="3" Columns="1" runat="server" Width="34px"></asp:TextBox>
</td>
<td>
<asp:TextBox ID="TextBox4" runat="server" Width="61px"></asp:TextBox>
</td>
<td>
<asp:TextBox ID="TextBox5" runat="server" Width="59px"></asp:TextBox>
</td>
<td>
<asp:TextBox ID="TextBox6" runat="server" Width="45px"></asp:TextBox>
</td>
<td>
<asp:TextBox ID="TextBox7" runat="server" Width="45px"></asp:TextBox>
</td>
<td>
<asp:TextBox ID="TextBox8" runat="server" Width="30px"></asp:TextBox>
</td>
<td>
<asp:TextBox ID="TextBox9" ReadOnly="true" runat="server" Width="78px"></asp:TextBox>
</td>
<td>
<asp:TextBox ID="TextBox10" BackColor="LightPink" runat="server" Width="128px"></asp:TextBox>
</td>
<td>
<asp:TextBox ID="TextBox11" TextMode="Number" OnTextChanged="PacketNum_TextChanged" AutoPostBack="true" runat="server" Width="40px"></asp:TextBox>
</td>
<td>
<asp:DropDownList ID="DropDownList3" CssClass="ddl" runat="server">
<asp:ListItem Text="EA" Value="EA"></asp:ListItem>
<asp:ListItem Text="SqFt" Value="SqFt"></asp:ListItem>
<asp:ListItem Text="LnFt" Value="LnFt"></asp:ListItem>
</asp:DropDownList>
</td>
<td>
<asp:DropDownList ID="DropDownList4" CssClass="ddl" OnTextChanged="PacketNum_TextChanged" AutoPostBack="true" runat="server">
<asp:ListItem Text="EEI" Value="EEI" Selected="True"></asp:ListItem>
<asp:ListItem Text="Self" Value="Self"></asp:ListItem>
<asp:ListItem Text="Delta" Value="Delta"></asp:ListItem>
</asp:DropDownList>
</td>
<td>
<asp:TextBox ID="TextBox12" runat="server" Width="63px"></asp:TextBox>
</td>
<td>
<asp:TextBox ID="TextBox13" runat="server" Width="93px"></asp:TextBox>
</td>
</tr>
</table>
`
- 查询背后的代码
string CS = ConfigurationManager.ConnectionStrings["CARD"].ConnectionString;
using (SqlConnection con = new SqlConnection(CS))
{
String sql = "Select * from tbl_Measures_New1 Where Project_ID = @ProjectID and Project_ID like 'R%'";
SqlDataAdapter Msrda = new SqlDataAdapter(sql, con);
Msrda.SelectCommand.Parameters.AddWithValue("@ProjectID", ProjectID.Text);
DataSet Msrds = new DataSet();
Msrda.Fill(Msrds, "Msr");
ViewState["SQL"] = sql;
ViewState["Msr"] = Msrds;
if (Msrds.Tables["Msr"].Rows.Count > 0)
{
DataRow Msrdr = Msrds.Tables["Msr"].Rows[0];
AccountSelect.Text = Msrdr["Account_Num"].ToString();
OccCode.Text = Msrdr["Occ_Code"].ToString();
Measure.Text = Msrdr["Measure"].ToString();
Funding.SelectedValue = Msrdr["Funding_Source"].ToString();
PacketNum.Text = Msrdr["FPUD_Packet_No"].ToString();
EECNum.Text = Msrdr["EEC_Ref_Num"].ToString();
PTRNum1.Text = Msrdr["BPA_Ref_Num"].ToString();
VendorList.SelectedValue = Msrdr["Vendor_ID"].ToString();
SecVendorList.SelectedValue = Msrdr["Secondary_Vendor_ID"].ToString();
BidCost.Text = "$" + Msrdr["Measure_Cost"].ToString().Replace(".0000", ".00");
CustomerRebate.Text = "$" + Msrdr["Customer_Rebate"].ToString().Replace(".0000", ".00");
SavedKWh.Text = Msrdr["Saved_Kwh"].ToString();
Busbar.Text = Msrdr["BusBar_Kwh"].ToString();
BPACredit.Text = "$" + Msrdr["BPA_Credit"].ToString().Replace(".0000", ".00");
BPAReimburse.Text = "$" + Msrdr["BPA-FPUD_Reimburse"].ToString().Replace(".0000", ".00");
Units.Text = Msrdr["Measure_Units"].ToString();
if (Units.Text != "")
{
Units.Text = Msrdr["Measure_Units"].ToString();
}
else
{
Units.Text = "1";
}
UnitType.SelectedValue = Msrdr["Unit_Type"].ToString();
MsrLife.Text = Msrdr["Measure_Life"].ToString();
PTCS.Text = Msrdr["PTCS"].ToString();
Ducts.Text = Msrdr["PTCS_Ducts"].ToString();
Comm.Text = Msrdr["PTCS_Comm"].ToString();
}
答案 0 :(得分:0)
有几种方法可以做到这一点。如果要使用这样的表,请查看Repeater控件,或者查看使用GridView并将结果集绑定到该表。 (可以在GridView中有一个下拉列表和文本框。)
另外,请确保您的代码验证ProjectID.Text以避免任何潜在的SQL注入问题!