<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"> </span>
</a></li>
<li><a href="#">
<img src="images/img.gif" width="80" height="80" alt="image description" />
<span class="mask"> </span>
</a></li>
<li><a href="#">
<img src="images/img.gif" width="80" height="80" alt="image description" />
<span class="mask"> </span>
</a></li>--%>
</ul>
</asp:Panel>
</li>
I am trying to add images dynamically inside the Panel and then into the ul however i need to add only 3 images in one Panel and the next 3 in the other Panel.
My code behind is as follows:
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);
}
But all i get are 6 photos together which i don't want
Edit: PS I do have Panels upto 10 and i have added the code
Please help?
After the line Code listitem1.Controls.Add(anchor1);
replace it with below
if (j <= 2)
{
//panel 1
}
if (j > 2 && j <= 5)
{
//panel 2
}
if (j > 5 && j <= 8)
{
//panel 3
}
and so no
you need to only add in your if statement they are always being added to panel6 above.
if (3 < count1 && count1 <= 6) {
list2a.Controls.Add(listitem1)
Panel6.Controls.Add(list2a);
}
else
{
list2b.Controls.Add(listitem1);
Panel7.Controls.Add(list2b);
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.