Click here to Skip to main content
15,892,927 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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
C#
<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
C#
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();
                       }
Posted

Why aren't you using a DataGrid and binding the datasource to that?
 
Share this answer
 
Comments
jdykes1987 8-Jan-14 17:28pm    
I want the cells in the field to be editable all the time with out having to click the edit link on the row that needs to be updated. I have played with the idea of using a DataGrid, but didn't allow me the flexibility that I wanted. Thanks for the reply.
bowlturner 8-Jan-14 17:33pm    
You can do that with a datagrid. Look at the Column Templates, you can have it be editable all the times. The default value isn't but there are lots of ways around that.
If you want full control over the output, use a Repeater and define what you have here, inside the template for the repeater.
 
Share this answer
 
Comments
jdykes1987 8-Jan-14 17:29pm    
I'll look into using this method. Thanks for the reply. I've never used a repeater before. I'll let you know if I have a follow-up question(s).
Christian Graus 8-Jan-14 17:30pm    
Repeaters are very cool. by all means ask here if you have any questions that flow on from this one
jdykes1987 29-Jan-14 19:40pm    
Hey there, so I have been trying to use a Repeater to accomplish what I need to do, but when I setup the Repeater, it does not recognize the Textboxes, DropDownLists in the code behind file... It says this object does not exist in the current context.... I'm at a loss... Help!
My suggestion also to a use controls such as Gridview, Repeater or Datalist.
It can be easily editable , sortable, pagination etc. all with just using templates .

Reference on how to do it with Gridview control

http://www.aspdotnet-suresh.com/2011/02/how-to-inserteditupdate-and-delete-data.html[^]

http://www.c-sharpcorner.com/UploadFile/9f0ae2/gridview-edit-delete-and-update-in-Asp-Net/[^]

Hope this helps you.
 
Share this answer
 
Comments
Christian Graus 8-Jan-14 23:05pm    
Thanks for repeating the advice two other people gave already. I'm sure it helped.
JoCodes 8-Jan-14 23:30pm    
I just reiterated it with some links to refer.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900