locked
dropdown values according to rights RRS feed

  • Question

  • User639567535 posted

    I have form.aspx in that there is dropdown

    <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>



    There is mutlilpe values in that drodown ..

    e.g.
    Car
    Truck
    Bike
    Drink
    Factory



    There is another login page Login.aspx .
    Login code

    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 ?

    Thursday, August 25, 2016 6:05 AM

All replies

  • User1724605321 posted

    Hi ,

    When user login(validate the name/password credential) , you could name the user role(user or admin) . Then you could show the dropdownlist base on the role :

    1. pass parameter to sql query , find related items belong to the role .

    2. or hide the dropdownlist item :

        dropdownlist1.Items.FindByText("Text").Enabled = false;

    Best Regards,

    Nan Yu

    Friday, August 26, 2016 6:35 AM