How to arrange asp:Panel child controls in one line

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
Hello,
I have one Panel declared in aspx. Ill call it ParentPnl.
Now, I want to dynamically add a number of panels to ParentPnl.
I was sure that by default, the child panels will be displayed one after another, from left to right. What really happens is: the child panels displayed one under another, in one "column". Anything I tried so far didnt help.
Also, I tried to add Labels instead of panels, and it was OK, they were displayed in one "row", and not in a "column".
Here is the code that creates the child panels and adds them to Parent Panel:
(I changed variable names, so if I forgot to change somewhere, it may seem like it will not compile)

<div style="color:Black;background-color:White; <pre>
<span style="color:Blue; protected <span style="color:Blue; void createPanel(String strSIP, <span style="color:Blue; int nSNum)
{
<span style="color:Blue; int nSlt = 0;
<span style="color:Blue; int nPrt = 0;
String strType = String.Empty;
String strResult = String.Empty;
String strConnectedStation = String.Empty;
List<List<Panel>> lSlts = <span style="color:Blue; new List<List<Panel>>();

<span style="color:Blue; for (<span style="color:Blue; int i = 0; i < nSNum; i++)
{
List<Panel> lSlt = <span style="color:Blue; new List<Panel>();
lSts.Add(lSlt);
}

<span style="color:Blue; foreach (DataRow drPrt <span style="color:Blue; in dtTable.Rows)
{
nSlt = (<span style="color:Blue; int)drPrt[<span style="color:#A31515; "nSlt"];
nPrt = (<span style="color:Blue; int)drPrt[<span style="color:#A31515; "nPrt"];
strType = drPrt[<span style="color:#A31515; "Type"].ToString();
strResult = drPrt[<span style="color:#A31515; "result"].ToString();
strConnectedStation = drPrt[<span style="color:#A31515; "strConnectedStation"].ToString();

Panel pnlPrt = <span style="color:Blue; new Panel();
Label lblPrt = <span style="color:Blue; new Label();
Button btnPrt = <span style="color:Blue; new Button();

lblPrt.Text = <span style="color:#A31515; "&nbsp&nbsp" + nPrt.ToString();

btnPrt.CssClass = <span style="color:#A31515; "stylePrtIcon";

btnPrt.ID = String.Format(<span style="color:#A31515; "{0},{1},{2}", nSlt.ToString(), nPrt.ToString(), strConnectedStation);
btnPrt.Click += <span style="color:Blue; new EventHandler(showPrtDetails);

<span style="color:Blue; switch (strResult)
{
<span style="color:Blue; case <span style="color:#A31515; "SUCCESS":
lblPrt.CssClass = <span style="color:#A31515; "styleGreenRecIcon";
<span style="color:Blue; break;
<span style="color:Blue; case <span style="color:#A31515; "FAILURE":
lblPrt.CssClass = <span style="color:#A31515; "styleRedRecIcon";
<span style="color:Blue; break;
<span style="color:Blue; case <span style="color:#A31515; "UNKNOWN":
lblPrt.CssClass = <span style="color:#A31515; "styleGrayRecIcon";
<span style="color:Blue; break;
<span style="color:Blue; default:
<span style="color:Blue; break;
}

<span style="color:Blue; switch (strType)
{
<span style="color:Blue; case <span style="color:#A31515; "Unknown":
btnPrt.CssClass = <span style="color:#A31515; "styleQuestionIcon";
<span style="color:Blue; break;
<span style="color:Blue; case <span style="color:#A31515; "Computer":
btnPrt.CssClass = <span style="color:#A31515; "styleComputerIcon";
<span style="color:Blue; break;
<span style="color:Blue; case <span style="color:#A31515; "Printer":
btnPrt.CssClass = <span style="color:#A31515; "stylePrinterIcon";
<span style="color:Blue; break;
<span style="color:Blue; case <span style="color:#A31515; "Network_Device":
btnPrt.CssClass = <span style="color:#A31515; "styleNetworkIcon";
<span style="color:Blue; break;
<span style="color:Blue; case <span style="color:#A31515; "Server":
btnPrt.CssClass = <span style="color:#A31515; "styleServerIcon";
<span style="color:Blue; break;
<span style="color:Blue; case <span style="color:#A31515; "Linux":
btnPrt.CssClass = <span style="color:#A31515; "styleLinuxIcon";
<span style="color:Blue; break;
<span style="color:Blue; case <span style="color:#A31515; "Clock":
btnPrt.CssClass = <span style="color:#A31515; "styleClockIcon";
<span style="color:Blue; break;
<span style="color:Blue; default:
<span style="color:Blue; break;
}


pnlPrt.Controls.Add(lblPrt);
pnlPrt.Controls.Add(<span style="color:Blue; new LiteralControl(<span style="color:#A31515; "<br />"));
pnlPrt.Controls.Add(btnPrt);

lSlts[nSlt-1].Add(pnlPrt);
}

<span style="color:Blue; foreach(List<Panel> lPnlList <span style="color:Blue; in lSlts)
{
Panel pnlSlt = <span style="color:Blue; new Panel();

<span style="color:Blue; foreach (Panel pnl <span style="color:Blue; in lPnlList)
{
pnlSlt.Controls.Add(pnl);
}

parentPanel.Controls.Add(pnlSlt);
parentPanel.Controls.Add(<span style="color:Blue; new LiteralControl(<span style="color:#A31515; "<br />"));
}

<span style="color:Green; //the following labels displayed fine:
Panel pnl1 = <span style="color:Blue; new Panel();
<span style="color:Blue; for (<span style="color:Blue; int i = 0; i < 6; i++)
{
Label lbl = <span style="color:Blue; new Label();
lbl.Text = <span style="color:#A31515; "Blablablablablabla ";
pnl1.Controls.Add(lbl);
}
parentPanel.Controls.Add(pnl1);
}
[/code]
<br/>
Please Help me!

View the full article
 
Back
Top