ARTICLE

Data Binding from dataset to HTML table in .Net

Posted by Farooque Ali Articles | ADO.NET in C# September 27, 2010
In this article we are going to discuss Databinding from a Dataset to a HTML table during RUNTIME, if the table contains more than one detail for an order.
Reader Level:

Introduction:

In this article we are going to discuss Databinding from a Dataset to a HTML table during RUNTIME, if the table contains more than one detail for an order.

Below I have explained the things.

Create any table (I have mentioned my table below) in SQL database and bind the values into the new dataset. From the DataSet we need to bind the values into the table.

Table: Sample
  • Title Varchar
  • Qty int
  • Downloadable Varchar
  • Shipped Varchar
  • Price int
  • Shipping int
  • Tax int
  • Total int
Below code(Written in CodeBehind) is used to Bind the values in to the HTML table during RUNTIME:

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

Try this and let me know the feedbacks.

Login to add your contents and source code to this article
post comment
     

nice,good

Posted by mohamed eltigani Sep 28, 2012

gud

Posted by mangesh pagare Jun 16, 2012

gud

Posted by mangesh pagare Jun 16, 2012
COMMENT USING
PREMIUM SPONSORS
DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and add new content to existing PDF documents from within your applications.
Join a Chapter
SPONSORED BY
  • PDF reports have never been easier to create. With our included WYSIWYG Designer, you can layout your reports, set up your data source and let DynamicPDF ReportWriter do the rest.
Join a Chapter