如我有SQL查询出来的一个datatable
ID Name Price
1 小王 1000
2 小张 1200
3 小李 1300现在要求将他们绑定在我的一个HTML控件的Table上
注意 是一个Table
效果如
ID 1 2 3
Name 小王 小张 小李
Price 1000 1200 1300谢谢 急
ID Name Price
1 小王 1000
2 小张 1200
3 小李 1300现在要求将他们绑定在我的一个HTML控件的Table上
注意 是一个Table
效果如
ID 1 2 3
Name 小王 小张 小李
Price 1000 1200 1300谢谢 急
解决方案 »
- asp.net 怎么获取TreeView树形结构控件选定节点的“文本”路径 急
- 多语言的解决方案的疑问?????用.resx和数据库或其它的文件系统有什么分别吗?请明白的大哥帮俺解释一下?用.resx有什么好处??
- SQL 2000 企业管理器中 如何把一个表复制一份??
- 根据现有数据如何按规则排列
- Datagrid問題?
- How to mock a HttpContext & SimpleWorkerRequest ?
- VS无法调试 不报异常
- MVC 5引用问题,ViewBag不存在。
- 先到此报到一下!(顺便要一个显示数据表内容的例子.net的)献上20分以表谢意!
- C#开发的Web程序在调试运行过程中,总出现“句柄未初始化”错误,出错信息和调用函数如下
- |zyciis| 如何将一个datatable 绑定到一个 table 上 第二贴 绑定数据的话样式怎么办 急
- ASP.NET安装程序中如何修改web.config文件的内容?
动态生成一个tableTable t1 = new Table();
TableCell tcSystem = new TableCell();
tcSystem.Controls.Add(cbSystem);
TableRow trSystem = new TableRow();
trSystem.Controls.Add(tcSystem);
t1.Controls.Add(trSystem);
<%@ Import Namespace="System.Drawing" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><script runat="server"> DataTable dt = new DataTable();
protected void Page_Load(object sender, EventArgs e)
{
dt.Columns.Add("ID");
dt.Columns.Add("Name");
dt.Columns.Add("Price");
if (!IsPostBack)
{
dt.Rows.Add(dt.NewRow());
dt.Rows.Add(dt.NewRow());
dt.Rows.Add(dt.NewRow());
dt.Rows[0][0] = "1";
dt.Rows[0][1] = "小张";
dt.Rows[0][2] = "1000";
dt.Rows[1][0] = "2";
dt.Rows[1][1] = "小王";
dt.Rows[1][2] = "1200";
dt.Rows[2][0] = "2";
dt.Rows[2][1] = "小李";
dt.Rows[2][2] = "1300";
}
else
{
}
TableRow tr1 = new TableRow();
TableRow tr2 = new TableRow();
TableRow tr3 = new TableRow();
TableCell tc1 = new TableCell();
TableCell tc2 = new TableCell();
TableCell tc3 = new TableCell();
tc1.Text = "ID";
tr1.Cells.Add(tc1);
tc2.Text = "Name";
tr2.Cells.Add(tc2);
tc3.Text = "Price";
tr3.Cells.Add(tc3);
for (int i = 0; i < dt.Rows.Count; i++)
{
TableCell tcID = new TableCell();
tcID.Text = (string)dt.Rows[i][0];
tr1.Cells.Add(tcID);
TableCell tcName = new TableCell();
tcName.Text = (string)dt.Rows[i][1];
tr2.Cells.Add(tcName);
TableCell tcPrice = new TableCell();
tcPrice.Text = (string)dt.Rows[i][2];
tr3.Cells.Add(tcPrice);
}
this.Table1.Rows.Add(tr1);
this.Table1.Rows.Add(tr2);
this.Table1.Rows.Add(tr3);
}</script><html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>无标题页</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Label ID="Label1" runat="server"></asp:Label>
<asp:Table ID="Table1" runat="server" BorderStyle="Solid"></asp:Table>
</div>
</form>
</body>
</html>
private void TableBind()
{
DataTable dt = DataTable();
TableRow tblr = new TableRow();
tblr.BackColor = System.Drawing.Color.Tomato; foreach (DataColumn dc in dt.Columns)
{
TableCell tblc = new TableCell();
tblc.Text = dc.ColumnName.ToString();
tblr.Cells.Add(tblc);
}
this.tab1.Rows.Add(tblr); foreach (DataRow dr in dt.Rows)
{
TableRow tr2 = new TableRow();
for (int i = 0; i < dt.Columns.Count; i++)
{
TableCell tc = new TableCell();
tc.Text = dr[i].ToString();
tr2.Cells.Add(tc);
}
this.tab1.Rows.Add(tr2);
}
}
{ thisConnection.Open(); SqlDataAdapter thisAdapater = new SqlDataAdapter(sql, thisConnection); DataSet thisDataSet = new DataSet(); thisAdapater.Fill(thisDataSet); thisConnection.Close(); return thisDataSet;
}
<%@ Page Language="C#" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SqlClient" %>
<script runat="server">
protected void Page_Load(object sender, EventArgs e)
{
string connectionString = GetConnectionString();
Repeater.DataSource = GetDataSet(connectionString);
Repeater.DataBind();
} private DataSet GetDataSet(string connectionString)
{
DataSet dataSet; using (SqlConnection connection =
new SqlConnection(connectionString))
{
SqlDataAdapter adapter = new SqlDataAdapter(); adapter.TableMappings.Add("Table", "Suppliers"); connection.Open(); SqlCommand command = new SqlCommand(
@"SELECT TOP 20 Country, CompanyName, ContactName
FROM dbo.Suppliers ORDER BY Country;",
connection);
command.CommandType = CommandType.Text; adapter.SelectCommand = command; dataSet = new DataSet("Suppliers");
adapter.Fill(dataSet); connection.Close();
} return dataSet;
} static private string GetConnectionString()
{
return "Data Source=(local);Initial Catalog=Northwind;"
+ "Integrated Security=SSPI";
}
</script><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Repeater ID="Repeater" runat="server">
<HeaderTemplate>
<table border="1" cellpadding="0" cellspacing="0" width="80%" align="center">
<tr>
<td><strong>Country</strong></td>
<td><strong>CompanyName</strong></td>
<td><strong>ContactName</strong></td>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td>'<%# Eval("Country") %></td>
<td>'<%# Eval("CompanyName") %></td>
<td>'<%# Eval("ContactName") %></td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>
</div>
</form>
</body>
</html>