C# .NET - Master Page Dropdown - Asked By surya on 19-Sep-10 04:38 AM

 hi Friends
 
 i am creating master-page , in that one drop-down is there and auto-post-back = true.
 when i am selecting the drop-down list item . the page is refresh and redirect that particular page . now the problem is after redirecting the page , the drop-down list is cleared. so what should i do now the drop-down is not clear the value.

  i am trying like this, when i am selecting the drop-down i stored the value in Session but how to assign the session value in master page drop-down list in other pages.


this master page dropdown list : 

<asp:DropDownList ID="DropDownList1" runat="server" Width="280px" 
                                   AutoPostBack="True" 
                                   onselectedindexchanged="DropDownList1_SelectedIndexChanged">
                                   <asp:ListItem>--Select--</asp:ListItem>
                                   <asp:ListItem Value ="HomePage.aspx">EmployeeModule</asp:ListItem>
                                   <asp:ListItem Value="JobCard.aspx">JobCard</asp:ListItem>
                                   <asp:ListItem Value="LocationStracture.aspx">Location Setup</asp:ListItem>
                               </asp:DropDownList>

thanks and regards
surya
  

Web Star replied to surya on 19-Sep-10 04:43 AM
You can put code on codebehind page of  master page for assign the value of session variable to dropdownlist that stay with selected value item.
Sasha Kotlo replied to surya on 19-Sep-10 08:53 AM
To assign some particular value to a dropdownlist you can use the following code:

if(Session["valuename"] != null)
{
string valuetoset = Session["valuename"].ToString();
if (DropDownList1.Items.FindByValue(valuetoset) != null) { DropDownList1.SelectedValue = valuetoset; }
}

That's all.

Regards.
Goniey N (Mr. G) replied to surya on 19-Sep-10 09:37 AM
Make AutoPostBack As "False".

If Your AutoPostBack Is True Then When You Refresh Your Page It Will Also Refresh...


<asp:DropDownList ID="DropDownList1" runat="server" Width="280px"
                   AutoPostBack="False"
                   onselectedindexchanged="DropDownList1_SelectedIndexChanged">
                   <asp:ListItem>--Select--</asp:ListItem>
                   <asp:ListItem Value ="HomePage.aspx">EmployeeModule</asp:ListItem>
                   <asp:ListItem Value="JobCard.aspx">JobCard</asp:ListItem>
                   <asp:ListItem Value="LocationStracture.aspx">Location Setup</asp:ListItem>
                 </asp:DropDownList>



About Session Variable So For That Use Like below :

Session["UName"]=DropDownList1.SelectedItem.ToString();




Now In Another Page How It Is Used??

lblUName.Text=Session["UName'].ToString();





-- Hope This Will Help You...
hema latha replied to surya on 20-Sep-10 01:01 AM
If u dont want to postback the page then make "AutoPostBack = false".
 Or else it u want to postback the page and dont want to clear the dropdown
   add the bello code to code behind file when u binding the datasource to the dorpdown
   
    if(!IsPostBack)
   {
       dropdown1.datasource=ds;
       dropdown1.datatextfeild="";
      dropdown1.valuefeild="";
      dropdown1.databind();
   }