Sarvesh Sarvesh - 16 days ago 7
ASP.NET (C#) Question

How to change the position of divs in asp.net form dynamically

In the design of web form I have four divs


  • divGeneralDetails

  • divLanguageDetails

  • divLinkDetails

  • divOperationalDetails



Divs mentioned above are displayed vertically in the form.

My question is.
Depending on value in query string, i will have to change the order in which divs are displayed.

In my
Page_Load
event

string FirstDiv = Request.QueryString["id"];


if value of FirstDiv is equal to "General"

then order should be
- divGeneralDetails
- divLanguageDetails
- divLinkDetails
- divOperationalDetails


if value of
FirstDiv
is equal to "Operational"

then order should be
- divOperationalDetails
- divGeneralDetails
- divLanguageDetails
- divLinkDetails


How do I set this in
Page_Load
event. Any help will be highly appreciated.
Thanks

mjb mjb
Answer

You can use Panel.

Example:

<asp:Panel ID="panelMain" runat="server">
    <asp:Panel ID="divGeneralDetails" runat="server"></asp:Panel>
    <asp:Panel ID="divLanguageDetails" runat="server"></asp:Panel>
    <asp:Panel ID="divLinkDetails" runat="server"></asp:Panel>
    <asp:Panel ID="divOperationalDetails" runat="server"></asp:Panel>
</asp:Panel>

And then rearrange it add code behind:

panelMain.Controls.Clear();
panelMain.Controls.Add(divOperationalDetails);
panelMain.Controls.Add(divGeneralDetails);
panelMain.Controls.Add(divLanguageDetails);
panelMain.Controls.Add(divLinkDetails);