Pages

Thursday 31 January 2013

Bind Themes in Dropdownlist in asp.net

This is .aspx code
 <table cellpadding="2" cellspacing="2" width="100%" align="center">
        <tr>
            <td valign="top">
                <span style="font-family: Verdana; font-size: 10pt; font-weight: bold;">Theme Name</span>
            </td>
            <td valign="top">
                <asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="true"
                    Width="100px" onselectedindexchanged="DropDownList1_SelectedIndexChanged">
                </asp:DropDownList>
            </td>
        </tr>
    </table>
This is .asox.cs code
public void Page_PreInit()
    {


        if (Session["Theme"] == null)
        {
            Page.Theme = "";
        }
        else
        {
            Page.Theme = (string)Session["Theme"];
        }
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            DirectoryInfo themDir = new DirectoryInfo(Server.MapPath("App_Themes"));
            DropDownList1.DataTextField = "Name";
            DropDownList1.DataSource = themDir.GetDirectories();
            DropDownList1.DataBind();
            DropDownList1.Items.Insert(0, "Please Select");
        }

    }
    protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
    {
        Session["Theme"] = DropDownList1.SelectedValue;
        Server.Transfer(Request.FilePath);
    }

No comments:

Post a Comment