English 中文(简体)
利用强硬数据表建立动态表格
原标题:Using StringBuilder with DataSet to build dynamic table

Im利用StingBuilder,动态地从一个数据表上填充。 它分两部分,一是建立标签及其尺寸和栏目。 我已经开展了这项工作。 我所 st的是,如何打上“价值”的栏目,然后将座右铭放在楼面上。

表格有25栏,但通常只有17栏。 我还需要过滤第一栏。 我担心会如何做到这一点。 这是我迄今为止所做的。 所有这一切都从DS中删除了第一个价值。 我也可以改变指数编号,但在这种情况下,我确实不能这样做,因为每个栏的编号和索引都不为人知。

            DataSet valuesSet = getBlendInfo.GetProcessValues(reqID);

            foreach (DataRow dRow in valuesSet.Tables[0].Rows)
            {
                tblString.Append("<td>");
                tblString.Append(dRow[0].ToString());
                tblString.Append("</td>");
            }
最佳回答

Try:

DataSet valuesSet = getBlendInfo.GetProcessValues(reqID);
foreach (DataRow dRow in valuesSet.Tables[0].Rows)
{
    bool firstColumn = true;
    foreach (DataColumn dbColumn in valuesSet.Tables[0].Columns)
    {
        if (firstColumn)
            firstColumn = false;
        else
        {
            tblString.Append("<td>");
            tblString.Append(dRow[dbColumn].ToString());
            tblString.Append("</td>");
        }
    }
}
问题回答

you just need to use a nested loop, something like this:

foreach (DataRow row in table.Rows)
{
    tblString.Append("<tr>");

    for (int i = 0; i < table.Columns.Count; i++)
    {
        tblString.Append("<td>");
        tblString.Append(row[i].ToString());
        tblString.Append("</td>");
    }

    tblString.Append("</tr>");
}

阅读前<代码>null查询<>

//This way you can create a row with the column names
blString.Append("<tr>");

foreach(var col in valuesSet.Tables[0].Columns)
{
    tblString.Append("<td>");
    tblString.Append(col.ToString());
    tblString.Append("</td>");
}

blString.Append("</tr>");




相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Transaction handling with TransactionScope

I am implementing Transaction using TransactionScope with the help this MSDN article http://msdn.microsoft.com/en-us/library/system.transactions.transactionscope.aspx I just want to confirm that is ...

System.Web.Mvc.Controller Initialize

i have the following base controller... public class BaseController : Controller { protected override void Initialize(System.Web.Routing.RequestContext requestContext) { if (...

Microsoft.Contracts namespace

For what it is necessary Microsoft.Contracts namespace in asp.net? I mean, in what cases I could write using Microsoft.Contracts;?

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签