Click here to Skip to main content
15,886,693 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
am beginner i wanted to display database value into a html table using jquery and c#.the condition is when i submit a search button the all value display on another aspx form on page load
Posted
Comments
bbirajdar 3-Nov-13 23:37pm    
Any particular reason for using HTML only ? You can have a larger set of options if you use GridView instead

1 solution

You can use ajax post for doing this. You have to create a web method and that web method should bring the value from database and you can use jquery to call that web method and in that web method you can construct your html table by using string builder and by using jquery you can bind your table inside a div.

Use this code carrefully

C# Code

XML
[WebMethod]
        public static string GetServices(string entry_id)
        {
            string HtmlData = string.Empty;
            try
            {
                HtmlData = GetString();
            }
            catch (Exception ex)
            {
                /////
            }
            return HtmlData;
        }

        private static string GetString()
        {
            //write the code for bring value from database

            DataTable table = new DataTable();//bring all your value in to this datatable
            DataRowCollection drows = table.Rows;
            StringBuilder HTML = new StringBuilder();
            HTML.AppendLine("<table>");
            foreach (DataRow dr in drows)
            {
                HTML.AppendLine("<tr>");
                HTML.AppendFormat("<td>{0}</td>\n", dr["FieldName"]);
                HTML.AppendLine("</tr>");

            }
            HTML.AppendLine("</table>");
            HTML.AppendLine("</div>");
            return HTML.ToString();
        }


Jquery

Import the jquery library here

<script type="text/javascript">
$("#button").click(function(){
storeInfo();
});

function storeInfo() {
var elem_id = elem.attr('id');
var page_url = 'Pagename.aspx/GetServices';
$.ajax({
type: 'POST',
url: page_url,
data: "",
contentType: 'Application/json; charset=utf-8',
dataType: 'json',
success: function (details)
{ $("#storeInformation").html(details.d); }
});
return false;
}
});
</script>


Html Code

XML
<div id="storeInformation">

   </div>



Or use this

http://www.c-sharpcorner.com/uploadfile/farooque84/data-binding-from-dataset-to-html-table-in-net/[^]
 
Share this answer
 

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