我在页面上放了个table,我想把数据库里面的数据放到这个表里面,不知该怎么做

梦回自己 2011-08-22 10:38:51
我在页面上放了个table,我想把数据库里面的数据放到这个表里面,不知该怎么做
...全文
128 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
梦回自己 2011-08-24
  • 打赏
  • 举报
回复
[Quote=引用 8 楼 huangwenquan123 的回复:]
引用 7 楼 kicydomcs 的回复:
直接一个表格不行吗
可以啊 子夜不是给例子了?
或者拼接输出也可以。
[/Quote]
“拼接输出”是什么意思啊
kidong 2011-08-23
  • 打赏
  • 举报
回复
用10楼的就行啦 那个就是最常用的 不懂怎么用的话就追问哦
木______木 2011-08-23
  • 打赏
  • 举报
回复

<table>
<asp:Repeater ID="rptData" runat="server" >
<ItemTemplate>
<tr>
<td><%#Eval("userID")%></td>//<%#Eval("这是你的model里的字段")%>
<td><%#Eval("userName")%></td>
</tr>
</ItemTemplate>
</asp:Repeater>
</table>




protected void Page_Load(object sender, EventArgs e)
{

if(!isPostBack)
{
DataSet ds = DBHelper.ExcuteSql("select * from user");
rptData.DataSource = ds;
rptData.DataBind();
}
}

ycproc 2011-08-23
  • 打赏
  • 举报
回复
把数据在前台展现 有两种方式

第一就是拼接 HTML 就是子夜的方式

第二就是在前台放 repeater等等控件 后台把数据源指定就行了

对于新人来说 还是采用第二种方式做
huangwenquan123 2011-08-23
  • 打赏
  • 举报
回复
[Quote=引用 7 楼 kicydomcs 的回复:]
直接一个表格不行吗
[/Quote]可以啊 子夜不是给例子了?
或者拼接输出也可以。
梦回自己 2011-08-23
  • 打赏
  • 举报
回复
直接一个表格不行吗
梦回自己 2011-08-23
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 langzi588 的回复:]
将数据控件放到table的tr里面,将数据查询出来绑定到数据空间里面,效果就是table显示数据
[/Quote]
一定要用数据控件吗
langzi588 2011-08-23
  • 打赏
  • 举报
回复
将数据控件放到table的tr里面,将数据查询出来绑定到数据空间里面,效果就是table显示数据
梦回自己 2011-08-23
  • 打赏
  • 举报
回复
我想把数据库里面的数据放到table里面啊
SomethingJack 2011-08-22
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 wxr0323 的回复:]
HTML code

<%@ Page language="C#" AutoEventWireup="true" %>
<%@ Import Namespace="System.Drawing" %>

<html>
<head>
<script runat="server">
private void Page_Load(objec……
[/Quote]
他指的应该是后台拼接之后 table显示
子夜__ 2011-08-22
  • 打赏
  • 举报
回复
<%@ Page language="C#" AutoEventWireup="true" %>
<%@ Import Namespace="System.Drawing" %>

<html>
<head>
<script runat="server">
private void Page_Load(object sender, System.EventArgs e)
{
// Create a TableItemStyle object that can be
// set as the default style for all cells
// in the table.
TableItemStyle tableStyle = new TableItemStyle();
tableStyle.HorizontalAlign = HorizontalAlign.Center;
tableStyle.VerticalAlign = VerticalAlign.Middle;
tableStyle.Width = Unit.Pixel(100);

// Create more rows for the table.
for (int i = 2; i < 10; i++)
{
TableRow tempRow = new TableRow();
for (int j = 0; j < 3; j++)
{
TableCell tempCell = new TableCell();
tempCell.Text = "(" + i + "," + j + ")";
tempRow.Cells.Add(tempCell);
}
Table1.Rows.Add(tempRow);
}

// Apply the TableItemStyle to all rows in the table.
foreach (TableRow r in Table1.Rows)
foreach (TableCell c in r.Cells)
c.ApplyStyle(tableStyle);

// Create a header for the table.
TableHeaderCell header = new TableHeaderCell();
header.RowSpan = 1;
header.ColumnSpan = 3;
header.Text = "Table of (x,y) Values";
header.Font.Bold = true;
header.BackColor = Color.Gray;
header.HorizontalAlign = HorizontalAlign.Center;
header.VerticalAlign = VerticalAlign.Middle;

// Add the header to a new row.
TableRow headerRow = new TableRow();
headerRow.Cells.Add(header);

// Add the header row to the table.
Table1.Rows.AddAt(0, headerRow);
}
</script>
</head>

<body>
<form runat="server">
<h1>TableCell Example</h1>
<asp:table id="Table1" runat="server" CellPadding="3" CellSpacing="3">
<asp:TableRow>
<asp:TableCell Text="(0,0)"></asp:TableCell>
<asp:TableCell Text="(0,1)"></asp:TableCell>
<asp:TableCell Text="(0,2)"></asp:TableCell>
</asp:TableRow>
<asp:TableRow>
<asp:TableCell Text="(1,0)"></asp:TableCell>
<asp:TableCell Text="(1,1)"></asp:TableCell>
<asp:TableCell Text="(1,2)"></asp:TableCell>
</asp:TableRow>
</asp:table>
</form>
</body>
</html>
飘零一叶 2011-08-22
  • 打赏
  • 举报
回复
在table里面放个gridview,把从数据库读出来的数据绑定到
gridview上

62,254

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧