Click here to Skip to main content
15,884,472 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
dropdown values according to rightsI have form.aspx in that there is dropdown

ASP.NET
<asp:Label ID="Label3" runat="server" Text="Select values"></asp:Label>
   <asp:DropDownList ID="regiondrop" runat="server" AutoPostBack="True"
   onselectedindexchanged="regiondrop_SelectedIndexChanged">
   </asp:DropDownList>

   <asp:RequiredFieldValidator controltovalidate="regiondrop" ID="RequiredFieldValidator1" runat="server" ErrorMessage="Select Region">
   </asp:RequiredFieldValidator>


What I have tried:

There is mutlilpe values in that drodown ..

C#
e.g.
   Car
   Truck
   Bike
   Drink
   Factory


There is another login page Login.aspx .
Login code

C#
protected void Button1_Click(object sender, EventArgs e)
       {
           try
           {
               //Label1.BackColor = "F8D8D7";
               loginmethod(txt_us.Text, txt_pwd.Text);

               Response.Redirect("WebForm1.aspx");
           }
           catch( Exception )
           {
               Label1.Text = ("Incorrect UserName/Password");
               Label1.Visible = true;
           }
           txt_us.Text = "";
           txt_pwd.Text = "";


       }
       public bool  loginmethod(string UserName,string Password)
       {
           TrackDataEntities1 td = new TrackDataEntities1();

          splogin1_Result sp = td.splogin1(UserName, Password).FirstOrDefault();
          if(sp.Password==txt_pwd.Text)
          {
              return true;
          }
          else
          {
              return false;
          }



       }


Now there is two users .. admin and user . Now i want when admin login then with their id and password then he see some values from this list and when user login then he will see some values from this list for example when admin login then he may able to see only Factory value and when user login then he able to see all values except factory

how i do this ?
Posted
Comments
F-ES Sitecore 25-Aug-16 5:06am    
If (userisadmin)
{
regiondrop.DataSource = adminListOfData;
}
else
{
regiondrop.DataSource = nonAdminListOfData;
}

This is fairly straightforward.
super_user 25-Aug-16 5:53am    
but dropdown list control is in form.aspx and login code is in login.aspx.. . there is several values in dropdown which i fetch from database and fill in dropdown using linq query ..
F-ES Sitecore 25-Aug-16 5:57am    
You need a mechanism that lets your site know at a global level if the user is logged, and maybe also what their role is. This is usually done using the Session. So after they log in set something like

Session["UserID"] = userID;

you could use the username if that's all you have. Other pages can then check if Session["UserID"] is populated, and if it is work out the users role\rights from their login info.
super_user 25-Aug-16 6:05am    
yes i know that but the problem is all values are in one table and i use this query for filling drodown

var list = tea.tblReg.AsEnumerable()
.Where(x => !x.Region.Any(char.IsDigit) && (x.Region != ""))
.GroupBy(x => x.Region)
.Select(x => new { Region = x.Key, Value = x.Key })
.ToList();




if (!Page.IsPostBack)
{
regiondrop.DataSource = list;
regiondrop.DataTextField = "Region";
regiondrop.DataValueField = "Region";
regiondrop.DataBind();

Label4.Visible = false;



}
F-ES Sitecore 25-Aug-16 6:10am    
You need some way of knowing which fields are to be used for admin and non-admin. Maybe have an extra field on your Region table that says if the field is valid for admin users or not, and then you include that in the Where.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900