从SQL DataSet中返回asp:Table中的多行 [英] Returning multiple rows in asp:Table from SQL DataSet
本文介绍了从SQL DataSet中返回asp:Table中的多行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
下面是我的网站的一部分,其中数据是由后面的代码中的SQL查询加载的,下面列出了...我的问题是如何复制第二个< < b< < table> 如果在查询后面的代码中返回了多条记录...任何指针或提示都表示赞赏...
- .aspx表
Below is a section of my site where the data is being loaded by a sql query in the code behind, which is listed below as well... My question is how can I duplicate the second < tr > in the < table > if there are more than one record returned in the code behind query... Any pointers or tips are appreciated...
-- .aspx Table
<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="Delete" ImageUrl="Images/DeletePage.gif" runat="server"></asp:ImageButton>
</td>
<td>
<asp:DropDownList ID="PacketNum" CssClass="ddl" Width="60px" OnTextChanged="PacketNum_TextChanged" AutoPostBack="true" runat="server"></asp:DropDownList>
</td>
<td>
<asp:DropDownList CssClass="ddl" ID="EECNum" Width="115px" OnTextChanged="EECNum_TextChanged" AutoPostBack="true" runat="server"></asp:DropDownList>
</td>
<td class="auto-style1">
<asp:TextBox ID="PTRNum1" Width="100px" runat="server"></asp:TextBox>
</td>
<td>
<asp:TextBox ID="Measure" Width="350px" runat="server" Wrap="true" ></asp:TextBox>
</td>
<td>
<asp:TextBox ID="PTCS" MaxLength="3" Columns="1" runat="server" Width="34px"></asp:TextBox>
</td>
<td>
<asp:TextBox ID="Ducts" runat="server" Width="61px"></asp:TextBox>
</td>
<td>
<asp:TextBox ID="Comm" runat="server" Width="59px"></asp:TextBox>
</td>
<td>
<asp:TextBox ID="Busbar" runat="server" Width="45px"></asp:TextBox>
</td>
<td>
<asp:TextBox ID="SavedKWh" runat="server" Width="45px"></asp:TextBox>
</td>
<td>
<asp:TextBox ID="MsrLife" runat="server" Width="30px"></asp:TextBox>
</td>
<td>
<asp:TextBox ID="BPACredit" ReadOnly="true" runat="server" Width="78px"></asp:TextBox>
</td>
<td>
<asp:TextBox ID="BPAReimburse" BackColor="LightPink" runat="server" Width="128px"></asp:TextBox>
</td>
<td>
<asp:TextBox ID="Units" TextMode="Number" OnTextChanged="PacketNum_TextChanged" AutoPostBack="true" runat="server" Width="40px"></asp:TextBox>
</td>
<td>
<asp:DropDownList ID="UnitType" 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="Funding" 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="BidCost" runat="server" Width="63px"></asp:TextBox>
</td>
<td>
<asp:TextBox ID="CustomerRebate" runat="server" Width="93px"></asp:TextBox>
</td>
</tr>
</table>
- 背后的代码
-- Code Behind
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();
}
推荐答案
+ Msrdr [ Measure_Cost]。ToString()。替换( 。0000, 。00);
CustomerRebate.Text =
" + Msrdr["Measure_Cost"].ToString().Replace(".0000", ".00"); CustomerRebate.Text = "
+ Msrdr [< span class =code-string> Customer_Rebate]。ToString()。替换( 。0000, 。00);
SavedKWh.Text = Msrdr [ Saved_Kwh]。ToString( );
Busbar.Text = Msrdr [ BusBar_Kwh]。ToString();
BPACredit.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_Credit"].ToString().Replace(".0000", ".00"); BPAReimburse.Text = "
这篇关于从SQL DataSet中返回asp:Table中的多行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文