特定间隔后如何使用datalist [英] How to use to datalist after particular interval

查看:58
本文介绍了特定间隔后如何使用datalist的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在第一个数据主义者计算三次后添加第二个数据列表

I want to add second data list after three count of first datalist

foreach (DataRow dr in objDT_PostedNews.Rows)
    {

        count++;
        label1.Text = dr["Particular"].ToString();
        PlaceHolder1.Controls.Add(new Literal { Text = label1.Text });
        if (count > 2)
        {
            while(i< objDT_Ad.Rows.Count)
            {
                PlaceHolder1.Controls.Add(new Literal { Text = objDT_Ad.Rows[i]["Particular"].ToString() });
                count = 0;
                i++;
                break;
            }
        }
    }





我尝试过:



我用占位符试了一下。



PlaceHolder1.Controls.Add(new Literal {text = objDT_Ad.Rows [i] [special]。ToString()});



但我想用datalist做。



What I have tried:

I tried it with placeholder.

PlaceHolder1.Controls.Add(new Literal { Text = objDT_Ad.Rows[i]["Particular"].ToString() });

but I want to do it with datalist.

推荐答案

您对循环的使用通常是

Your usage of the loop is usual
if (count > 2)
{
    while(i< objDT_Ad.Rows.Count)
    {
        PlaceHolder1.Controls.Add(new Literal { Text = objDT_Ad.Rows[i]["Particular"].ToString() });
        count = 0;
        i++;
        break;
    }
}



由于循环不循环,如果更简单地使用 if


Since the loop don't loop, if simpler to use a if

if (count > 2)
{
    if (i< objDT_Ad.Rows.Count)
    {
        PlaceHolder1.Controls.Add(new Literal { Text = objDT_Ad.Rows[i]["Particular"].ToString() });
        count = 0;
        i++;
    }
}





您的示例代码不是自主的,可以设计的不多它。可以更好地充实代码以便运行。

您想要的初始数据和结果的样本也会很好。



your sample code is not autonomous, not much can be devised from it. Would be better flesh up the code so that is can be run.
A sample of initial data and result you want would be nice too.


这篇关于特定间隔后如何使用datalist的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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