Tuesday, April 23, 2013

Data Binding from dataset to HTML table in .Net

public void BindData(int iOrderId)
{
    DataSet ds = new DataSet();
    ds = objorders.GetOrderStatus(iOrderId);
    if (ds.Tables.Count > 0)
    {
        Response.Write("<table border='1' cellpadding='2'  WIDTH='75%' ");
        Response.Write("<tr><th>Title</th><th>Qty</th><th>Downloadable?</th><th>Shipped?</th><th>Price</th><th>Shipping</th><th>Tax</th><th>Total</th>");
        Response.Write("</tr>");
        if (ds.Tables.Count > 0)
        {
            for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
            {
                Response.Write("<tr>");
                Response.Write("<td> " + ds.Tables[0].Rows[i]["product_name"].ToString() + " </td>");
                Response.Write("<td> " + ds.Tables[0].Rows[i]["Product_Qty"].ToString() + " </td>");
                Response.Write("<td> " + "NO" + "  </td>");
                Response.Write("<td> " + "YES" + "  </td>");
                Response.Write("<td> " + ds.Tables[0].Rows[i]["Product_Cost"].ToString() + " </td>");
                Response.Write("<td> " + 1.00 + " </td>");
                Response.Write("<td> " + 1.00 + "  </td>");
                Response.Write("<td> " + ds.Tables[0].Rows[i]["store_product_final_cost_total"].ToString() + " </td>");
                Response.Write("</tr>");
            }
            Response.Write("<tr>");
            Response.Write("<td colspan=5> Order-Level shiping cost() </td>");
            Response.Write("<td> " + 1.00 + "  </td>");
            Response.Write("<td> " + 1.00 + "  </td>");
            Response.Write("<td> " + ds.Tables[0].Rows[0]["store_product_final_cost_total"].ToString() + " </td>");
            Response.Write("</tr>");
            Response.Write("<tr>");
            Response.Write("<td colspan=7> Total on Discover xxxxxxxxxxcc9124 </td>");
            Response.Write("<td> " + ds.Tables[0].Rows[0]["store_order_final_cost_total"].ToString() + " </td>");
            Response.Write("</tr>");
            Response.Write("</table>");
        }
    }
    else
    {
        //lblinform.Text = "No data found.";
    }
}

In the above code I have added the Stored procedure (Which is joined with Multiple table and Aggregate functions) with the new Dataset. You can able to create this by using Single table also.

Output:

The output will be shown like this

1.gif

No comments:

Post a Comment