使用数据库动态创建div [英] creating div dynamcially using database

查看:90
本文介绍了使用数据库动态创建div的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用数据库创建动态div



在数据库记录中如下

在LatestNewsMaster表中记录如下



ID主题描述链接

1账户账户费用页面Accountsfees.aspx

2缺陷缺陷邮件报告Defects.aspx



我的代码如下



string constr = ConfigurationManager.ConnectionStrings [Reception2_DB]。ConnectionString;

使用(SqlConnection con = new SqlConnection(constr))

{

sing(SqlCommand cmd = new SqlCommand(select subject,Description,Link from LatestNewsMaster活跃<>'d'))

{

cmd.Connection = con;

using(SqlDataAdapter sda = new SqlDataAdapter(cmd))

{

DataTable dt = new DataTable();

sda.Fill(dt);

for(int i = 0; I< dt.rows.count;> {

lblSub.Text + = dt.Rows [i] [0] .ToString()。Trim()+
;

lbldesc.Text + = dt.rows [i] [1] .ToString()。Trim()+
;

llbLink.Text + = dt.rows [i] [2] .ToString( ).Trim()+
;

}

}

}





当我运行上面的代码输出如下



账户(主题显示自数据库)

缺陷(主题显示自数据库)

帐户费用页面(说明显示自数据库)

缺陷邮件报告(说明显示自数据库)

Accountsfees.aspx(从数据库显示的链接)

Defects.aspx(从数据库显示的链接)



但我希望上面的显示如下:



主题说明链接



帐户帐户费用页面Accountsfees.aspx

缺陷邮件报告缺陷.aspx







忘记上面输出我在上面代码中要做的更改。

i want to create dynamically div using database

In database record as follows
In LatestNewsMaster table record as follows

ID Subject Description Link
1 Accounts Accounts fee page Accountsfees.aspx
2 Defects Defects mail report Defects.aspx

my code as follows

string constr = ConfigurationManager.ConnectionStrings["Reception2_DB"].ConnectionString;
using (SqlConnection con = new SqlConnection(constr))
{
sing (SqlCommand cmd = new SqlCommand("select Subject,Description,Link from LatestNewsMaster where active <> 'd'"))
{
cmd.Connection = con;
using (SqlDataAdapter sda = new SqlDataAdapter(cmd))
{
DataTable dt = new DataTable();
sda.Fill(dt);
for (int i = 0; i<dt.rows.count;> {
lblSub.Text += dt.Rows[i][0].ToString().Trim() + "
";
lbldesc.Text += dt.rows[i][1].ToString().Trim() +"
";
llbLink.Text += dt.rows[i][2].ToString().Trim() + "
";
}
}
}


When i run the above code output as follows

Accounts (Subject Displayed from the database)
Defects (Subject Displayed from the database)
Accounts fee page (Description Displayed from the database)
Defects mail report (Description Displayed from the database)
Accountsfees.aspx (Link Displayed from the database)
Defects.aspx (Link Displayed from the database)

But i want the above ouptut to be displayed as follows

Subject Description Link

Accounts Accounts fee page Accountsfees.aspx
Defects Defects mail report Defects.aspx



forgetting above output what changes i have to made in my above code.

推荐答案

用行构建一个Html表或GridView。你需要一个类似于结构的表。 Fir GridView,你必须指定像...

Build an Html table or GridView with the rows. You need a table like structure. Fir GridView, you have to assign like...
GridViewId.DataSource = dt;
GridViewId.DataBind();


这篇关于使用数据库动态创建div的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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