Click here to Skip to main content
15,888,351 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to add second data list after three count of first datalist
C#
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;
            }
        }
    }


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.
Posted
Updated 27-Aug-16 0:43am
v2
Comments
Karthik_Mahalingam 27-Aug-16 5:36am    
what does inner loop does?

1 solution

Your usage of the loop is usual
C#
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;
    }
}

Since the loop don't loop, if simpler to use a if
C#
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.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900