C# asp.net中动态生成的图像? --%%>

C# asp.net中动态生成的图像? --%%>,c#,asp.net,dynamic,panel,C#,Asp.net,Dynamic,Panel,我尝试在面板内动态添加图像,然后添加到ul中,但是我只需要在一个面板中添加3个图像,在另一个面板中添加下3个图像 我的代码如下: <li> <asp:Panel ID="Panel6" runat="server"> <ul id="list2a" runat="server">

我尝试在面板内动态添加图像,然后添加到ul中,但是我只需要在一个面板中添加3个图像,在另一个面板中添加下3个图像

我的代码如下:

<li>

                                    <asp:Panel ID="Panel6" runat="server">
                                    <ul id="list2a" runat="server">

                                    </ul>

                                    </asp:Panel>
                                </li>
                                <li>
                                    <asp:Panel ID="Panel7" runat="server">

                                    <ul id="list2b" runat="server">
                                        <%--<li><a href="#">
                                            <img src="images/img.gif" width="80" height="80" alt="image description" />
                                            <span class="mask">&nbsp;</span>
                                        </a></li>
                                        <li><a href="#">
                                            <img src="images/img.gif" width="80" height="80" alt="image description" />
                                            <span class="mask">&nbsp;</span>
                                        </a></li>
                                        <li><a href="#">
                                            <img src="images/img.gif" width="80" height="80" alt="image description" />
                                            <span class="mask">&nbsp;</span>
                                        </a></li>--%>
                                    </ul>
                                    </asp:Panel>
                                </li>
string query2=“从[User1]中选择[Pic_square],其中[FB_Id]在(从[Snapshot]中选择[FB_Id2],其中[FB_Id1]='812534558'和[Seeltr]='Seeltr','Seeltr='See Later'))从[Passive]中选择[Pic_square],其中([FB_Id]在[Snapshot]中选择[FB_Id2],其中[FB_Id1]='812534558'和[Seeltr='Seeltr='Seeltr稍后见')”)”;
var adt=新的SqlDataAdapter(query2,con);
ds1=新数据集();
自动填充(ds1);
int count1=ds1.Tables[0].Rows.Count;
对于(int j=0;jif(count1您只需要在if语句中添加它们,它们总是被添加到上面的panel6中

  string query2 = "SELECT [Pic_square] From [User1] WHERE ([FB_Id] IN (SELECT [Fb_Id2] FROM [Snapshot] WHERE [Fb_Id1]= '812534558' AND [Seeltr]='See Later')) UNION SELECT [Pic_square] From [Passive] WHERE ([FB_Id] IN (SELECT [Fb_Id2] FROM [Snapshot] WHERE [Fb_Id1]= '812534558' AND [Seeltr]='See Later'))";
        var adt = new SqlDataAdapter(query2, con);
        ds1 = new DataSet();
        adt.Fill(ds1);
        int count1 = ds1.Tables[0].Rows.Count;
        for (int j = 0; j < count1; j++)
        {
            HtmlGenericControl listitem1 = new HtmlGenericControl("li");
            HtmlGenericControl anchor1 = new HtmlGenericControl("a");
            Image im1 = new Image();
            im1.ImageUrl = (string)ds1.Tables[0].Rows[j].ItemArray[0];

            im1.Height = 80;
            im1.Width = 80;
            anchor1.Controls.Add(im1);
            //anchor1.Attributes.CssStyle.Add("div", "holder");
            listitem1.Controls.Add(anchor1);

            if(count1 <= 3)
           {
            list2a.Controls.Add(listitem1);
            Panel6.Controls.Add(list2a);
            }




            else if (3 < count1 && count1 <= 6)
            {


                list2b.Controls.Add(listitem1);
                Panel7.Controls.Add(list2b);
            }

 else if (6 < count1 && count1 <= 9)
            {
                //list2b.Controls.Add(listitem1);
                list2c.Controls.Add(listitem1);
                Panel8.Controls.Add(list2c);
            }
            else if (9 < count1 && count1 <= 12)
            {
                list2d.Controls.Add(listitem1);
                Panel9.Controls.Add(list2d);
               // list2b.Controls.Add(listitem1);
               // list2c.Controls.Add(listitem1);


            }
            else
            {
               // list2b.Controls.Add(listitem1);
                //list2c.Controls.Add(listitem1);
                //list2d.Controls.Add(listitem1);

                list2e.Controls.Add(listitem1);
                Panel10.Controls.Add(list2e);

            }

if(3listitem1.Controls.Add(anchor1)之后;
将其替换为以下内容

if (3 < count1 && count1 <= 6) {

     list2a.Controls.Add(listitem1)
     Panel6.Controls.Add(list2a);

}
else
{
      list2b.Controls.Add(listitem1);
      Panel7.Controls.Add(list2b);
}

如果(j 2&&j 5&&j)我只需要在Panel6中添加3个图像,然后在panel7中再添加3个图像,那么如果我有大量的面板,比如说我的屏幕中有10个,这将如何解决我的问题case@Vini你最初的问题有两个面板,我知道我没有放,因为代码变得非常大
if (j <= 2)
{
   //panel 1
}
if (j > 2 && j <= 5)
{
   //panel 2
}
if (j > 5 && j <= 8)
{
   //panel 3
}
and so no