我页面中的一个<table>有20行如(<td id=1 runat=server></td>...共有20个)
在后台我从数据库中select出一个DataTable我不知道这个DataTable到底有多少行,但是我要把我找出的这个DataTable每一行中name字段的内容要能在页面中对应行数的td中显示出来。
谁能帮下忙告诉我要怎么做能动态绑定?
在后台我从数据库中select出一个DataTable我不知道这个DataTable到底有多少行,但是我要把我找出的这个DataTable每一行中name字段的内容要能在页面中对应行数的td中显示出来。
谁能帮下忙告诉我要怎么做能动态绑定?
解决方案 »
- datagridview 切换数据源后滚动条不消失的问题
- 按钮单击时间
- 未处理的“System.StackOverflowException”类型的异常出现在 mscorlib.dll 中。能改下代码可以实现 递归,,将数据库中数据依次绑定到treeview1中吗???
- VS2003怎样实现 notifyIcon 气球提示。
- 那些书上讲类似WebBrowser1.Document.All(i).tagName这些东西,而且讲得比较精?请看一段代码:
- 请问C#怎样去捕获程序异常结束消息?
- 刷新页面问题
- 求救,DataGrid选定问题
- 请教:Winform下的DataGrid绑定ComboColumn的问题。
- 服务器接收httpwebrequest post的数据问题
- 方法与委托不匹配
- 高分请教报表问题
function binddata()
{
var table=document.getElementById("tabAllot");
var ntr;
var trr=table.rows[0];
var dt=getselectdata();
for(i=0;i<dt.Rows.length;i++)
{
if(i>table.rows.length-2)
{
if(table.rows.length%2==1)
{
ntr=document.getElementById("trmode1").cloneNode(3);
}
else
{
ntr=document.getElementById("trmode2").cloneNode(3);
}
ntr.childNodes[0].firstChild.innerText=dt.Rows[i]["BILLNO"];
ntr.childNodes[0].firstChild.title=dt.Rows[i]["OPERATIONNO"];
ntr.childNodes[1].innerText=dt.Rows[i]["STATE"]=="0"?"待分派":dt.Rows[i]["STATE"]=="1"?"已分派":dt.Rows[i]["STATE"]=="2"?"已结束":"未知状态";
ntr.childNodes[2].innerText=dt.Rows[i]["EQUITNAME"];
ntr.childNodes[3].innerText=dt.Rows[i]["BRAND"];
ntr.childNodes[4].innerText=dt.Rows[i]["TYPE"];
ntr.childNodes[5].innerText=dt.Rows[i]["ERRDESC"];
ntr.childNodes[6].innerText=dt.Rows[i]["CLIENTNAME"];
trr.parentNode.appendChild(ntr);
}
else
{
var tmd=table.rows[i+1];
tmd.childNodes[0].firstChild.innerText=dt.Rows[i]["BILLNO"];
tmd.childNodes[0].firstChild.title=dt.Rows[i]["OPERATIONNO"];
tmd.childNodes[1].innerText=dt.Rows[i]["STATE"]=="0"?"待分派":dt.Rows[i]["STATE"]=="1"?"已分派":dt.Rows[i]["STATE"]=="2"?"已结束":"未知状态";
tmd.childNodes[2].innerText=dt.Rows[i]["EQUITNAME"];
tmd.childNodes[3].innerText=dt.Rows[i]["BRAND"];
tmd.childNodes[4].innerText=dt.Rows[i]["TYPE"];
tmd.childNodes[5].innerText=dt.Rows[i]["ERRDESC"];
tmd.childNodes[6].innerText=dt.Rows[i]["CLIENTNAME"];
}
}
while(table.rows.length-1>dt.Rows.length)
{
if(table.rows.length>3)
{
table.deleteRow(table.rows.length-1);
}
else if(dt.Rows.length<2)
{
if(dt.Rows.length==0)
{
table.rows[1].childNodes[0].firstChild.innerText="";
table.rows[1].childNodes[0].firstChild.title="";
table.rows[1].childNodes[1].innerText="";
table.rows[1].childNodes[2].innerText="";
table.rows[1].childNodes[3].innerText="";
table.rows[1].childNodes[4].innerText="";
table.rows[1].childNodes[5].innerText="";
table.rows[1].childNodes[6].innerText="";
}
table.rows[2].childNodes[0].firstChild.innerText="";
table.rows[2].childNodes[0].firstChild.title="";
table.rows[2].childNodes[1].innerText="";
table.rows[2].childNodes[2].innerText="";
table.rows[2].childNodes[3].innerText="";
table.rows[2].childNodes[4].innerText="";
table.rows[2].childNodes[5].innerText="";
table.rows[2].childNodes[6].innerText="";
break;
}
}
}
----------------------
我使用的第1行为 列头,2,3行为模板 因为有些样式设置。你也可以只自己直接插入行和单元格
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
DisplayData();
}
protected void DisplayData()
{
DataTable dt = 你的select出来的datatable;
for (int i = 0; i < dt.Rows.Count; i++)
{ HtmlTableCell td = this.Page.FindControl("td" + i.ToString()) as HtmlTableCell;
if (td != null)
{
td.InnerHtml = dt.Rows[i]["name"];
}
}
}
html<div>
<table>
<tr>
<td id="td1" runat="server">
</td>
</tr>
<tr>
<td id="td2" runat="server">
</td>
</tr>
<tr>
<td id="td3" runat="server">
</td>
</tr>
<tr>
<td id="td4" runat="server">
</td>
</tr>
</table>
</div>
<asp:Repeater id="rp1" runat="server">
<itemtemplate>
<tr><td id='<%#Eval("NAME")%>'></td></tr>
</itemtemplate>
</asp:Repeater>
</table>