使用数据库我想使用C#在Asp.Net中创建Div [英] Using Database I Want To Create Div In Asp.Net Using C#

查看:60
本文介绍了使用数据库我想使用C#在Asp.Net中创建Div的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的代码如下



My code as follows

StringBuilder sb = new StringBuilder();
for (int i = 0; i<1; i++)
{
     sb.Append(@"
    <div style="border: 1px solid black; padding: 10px; width: 200px;">
       Hello
    </div>");
 }
    lblErr.Controls.Add(new LiteralControl(sb.ToString()));



当我运行上面的代码并按如下方式执行输出时



将显示Hello在输出中没问题。





但是我想用数据库创建div



我的表格如下




When i run the above code and execute output as follows

Hello will be displayed in the output no problem.


But i want to create div using database

my table as follows

id    Link
1     Allcourselist.aspx
2     Accountspage.aspx



i想要在输出中创建2个div,因为上表中显示了两个记录。



如何使用c @在asp.net中使用数据库显示div。


i want to create 2 div in the output becuase two records is displaying in the above table.

how to display div using database in asp.net using c@.

推荐答案

首先,如评论中所述,你应该先看看转发器控制,因为它会自动为您执行此操作。通过C#代码生成html是非常糟糕的形式(尽管有时是必要的)。



但是,如果你想以你刚才调用数据库的方式这样做一个SqlCommand对象并返回一个DataReader。



然后遍历DataReader结果。
First off, as mentioned in the comments, you should first look into the repeater control because it will do this for you automatically. It's very bad form (although sometimes necessary) to be generating html via C# code.

However, if you want to do it the way you are just call the database with a SqlCommand object and return a DataReader.

Then loop through the DataReader results.


这篇关于使用数据库我想使用C#在Asp.Net中创建Div的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆