如何使用jquery和c#将数据库值显示到html表中

编程入门 行业动态 更新时间:2024-10-27 22:30:10
本文介绍了如何使用jquery和c#将数据库值显示到html表中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我是初学者我想使用jquery和c#将数据库值显示到html表中。条件是当我提交搜索按钮时,在页面上的另一个aspx表单上显示所有值

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

推荐答案

您可以使用ajax post来执行此操作。您必须创建一个Web方法,并且该Web方法应该带来数据库中的值,您可以使用jquery来调用该Web方法,并且在该Web方法中,您可以使用字符串构建器构建html表,并使用jquery绑定您的div内的桌子。 严格使用此代码 C#代码 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 [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 在这里导入jquery库 < script type =text / javascript>

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'; ("#button").click(function(){ storeInfo(); }); function storeInfo() { var elem_id = elem.attr('id'); var page_url = 'Pagename.aspx/GetServices';

.ajax({ 类型:'POST', url:page_url, 数据:, contentType:'Application / json; charset = utf-8', dataType:'json', 成功:功能(详情) { .ajax({ type: 'POST', url: page_url, data: "", contentType: 'Application/json; charset=utf-8', dataType: 'json', success: function (details) {

更多推荐

如何使用jquery和c#将数据库值显示到html表中

本文发布于:2023-10-23 23:14:29,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1522288.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:如何使用   数据库   jquery   html

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!