开发者

List full of rows of db data; how to load fields to labels?

I'm restructuring a practice project to convert to n-tier and OO, and I've hit a snag. I have 7 products, each with multiple fields, and a submission may have 0-7 products (no redundant instances). I store all the field data for all products with a relevant submission Id in List, which is a nested object inside the Submission object. All that to say, how do I pull the specific fields out of this list and load the labels on my page with them?

Example: Submission with Id 109 has Product EPL, and one field, Coverage, has a value of 800. I want label LblEplCov to contain that value. Code below.

data layer for products

  SqlCommand FidCmd = new SqlCommand(FiduciaryQuery, conn);
    SqlDataReader FidRead = new SqlDataReader();
    FidRead = FidCmd.ExecuteReader();

    Fiduciary TempFid = new Fiduciary();
    TempFid.Entity1 = FidRead.GetString(0);
    TempFid.PrimEx1 = FidRead.GetInt32(1);
    TempFid.Limit1 = FidRead.GetInt32(2);
    TempFid.SIR1 = FidRead.GetInt32(3);
    TempFid.Att1 = FidRead.GetInt32(4);
    TempFid.Premium1 = FidRead.GetInt32(5);
    TempFid.Sublim1 = FidRead.GetInt32(6);

    TempProdList.Add(TempFid);


    SqlCommand CrimeCmd = new SqlCommand(CrimeQuery, conn);

    SqlDataReader dr = null;
    List<Product> lstProduct = new List<Product>();

    dr = CrimeCmd.ExecuteReader();

    CrimeFidelity TempCrime = new CrimeFidelity();
    TempCrime.Entity1 = dr.GetString(0);
    TempCrime.Employees1 = dr.GetInt32(1);
    TempCrime.PrimEx1 = dr.GetInt32(2);
    TempCrime.LimA1 = dr.GetInt32(3);
    TempCrime.DedA1 = dr.GetInt32(4);
    TempCrime.PremA1 = dr.GetInt32(5);
    TempCrime.LimB1 = dr.GetInt32(6);
    TempCrime.DedB1 = dr.GetInt32(7);
    TempCrime.PremB1 = dr.GetInt32(8);

    TempProdList.Add(TempCrime);

    return TempProdList;

Business layer

    public static class ProductService
{
    public static List<Product&g开发者_JAVA技巧t; getProductById(string x)
    {
        return ProductDatabaseLayer.GetProductsById(x);       
    }    
}

presentation layer

    Submission sub = SubmissionService.getSubmissionByID(x);
    Customer cust = CustomerService.getCustomerById(sub.CustomerId1.ToString());
    Broker bro = BrokerService.getBrokerById(sub.BrokerId1.ToString());
    sub.Products1 = ProductService.getProductById(sub.SubmissionId1.ToString());

//Note: I imagine I would use an if !null block to determine whether a product is attached to the submission, but if there's a better way feel free to mention it.


It is difficult to understand your question, but I think you are looking for ways to dynamically build your user interface from a data-source.

If so, try using Repeaters

<asp:Repeater ID="InfrastructureRepeater" runat="server">
            <ItemTemplate>
             <asp:CheckBox ID="InfrastructureCheckbox" Text='<%#Eval("InfrastructureName") %>'
        runat="server" />                           
           </ItemTemplate>
        </asp:Repeater>

eg. You bind your datasource to the repeater and specify a template. It is also possible to access your items in the code behind like so:

foreach (RepeaterItem item in InfrastructureRepeater.Items)
{
  CheckBox infrastructureCheckBox = item.FindControl("InfrastructureCheckBox") as CheckBox;
 //Do something here
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜