Click here to Skip to main content
15,867,286 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I want to make my checkbox is enabled and disable when user login from my data

My syntaks in asp.net:

   if (Session["Berhasil"] != null)
        {
            Label1.Visible = true;
            Label1.Text = "Berhasil..";
            if(Label1 = "select * from cs100020 where countno=2 and status=3");
            {
                cbxinven.Enabled=true
                cbxfinadmin.Enabled=true
                cbxkaskecil.Enabled=true
                cbxemail.Enabled=false
                cbxsap.Enabled=false
                cbxpc.Enabled=false
                cbxuserad.Enabled=false
            }
            else (Label1="select * from cs100020 where countno=3 and status=3);
            {
                cbxinven.Enabled=false
                cbxfinadmin.Enabled=false
                cbxkaskecil.Enabled=false
                cbxemail.Enabled=true
                cbxsap.Enabled=true
                cbxpc.Enabled=true    
                cbxuserad.Enabled=true
            }    
        }


What I have tried:

Quote:
and i got error : Compilation Error Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

Compiler Error Message: CS1010: Newline in constant

Source Error:

Line 137: cbxuserad.Enabled=false Line 138: } Line 139: else (Label1="select * from cs100020 where countno=3 and status=3); Line 140: { Line 141: cbxinven.Enabled=false

Source File: d:\Sharing\Budiman\IAPHRM BACKUP 08022019\IapHRM_180119_Backup\ViewCS.aspx.cs Line: 139

Show Detailed Compiler Output:

Show Complete Compilation Source:
Posted
Updated 28-Jul-20 0:49am

Read the error message: it's pretty clear.
Compiler Error Message: CS1010: Newline in constant

It's saying that you started a constant (string) but didn't finish it before the end of the line.
So look at the line - it's line 139 so CTRL+G in the editor will almost certainly take you right there - and see if you can see what we do:
C#
else (Label1="select * from cs100020 where countno=3 and status=3);
                                                                 ^
                                                                 |
Where is the closing quote?
 
Share this answer
 
Comments
Budiman Oktavianus H.T 28-Jul-20 4:27am    
i try again and correct with your advice :

if (Session["Berhasil"] != null)
{
Label1.Visible = true;
Label1.Text = "Berhasil..";
if(Label1 = "select * from cs100020 where countno=2 and status=3");
{
cbxinven.Enabled=true;
cbxfinadmin.Enabled=true;
cbxkaskecil.Enabled=true;
cbxemail.Enabled=false;
cbxsap.Enabled=false;
cbxpc.Enabled=false;
cbxuserad.Enabled=false;
}
else(Label1 = "select * from cs100020 where countno=2 and status=3");
{
cbxinven.Enabled=false;
cbxfinadmin.Enabled=false;
cbxkaskecil.Enabled=false;
cbxemail.Enabled=true;
cbxsap.Enabled=true;
cbxpc.Enabled=true;
cbxuserad.Enabled=true;
}
}

and i got error again :

Compilation Error
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

Compiler Error Message: CS1525: Invalid expression term 'else'

Source Error:


Line 137: cbxuserad.Enabled=false;
Line 138: }
Line 139: else(Label1 = "select * from cs100020 where countno=2 and status=3");
Line 140: {
Line 141: cbxinven.Enabled=false;

Source File: d:\Sharing\Budiman\IAPHRM BACKUP 08022019\IapHRM_180119_Backup\ViewCS.aspx.cs Line: 139


Show Detailed Compiler Output:

Show Complete Compilation Source:

please, is my source code wrong?
OriginalGriff 28-Jul-20 4:59am    
OK, this one is difficult to see, but ... the compiler also gives you a warning about this ... treat warnings as errors!
Look at the "if" line: what does it end with?
A semicolon. What does that do? Ends the statement.
So
if (a == b) ;
if complete in itself, because if a is equal to b, it executes an empty statement - up to the semicolon. If a isn't equal to be, it ignores the empty statement.

Read your warnings:

CS0642 Possible mistaken empty statement

"if" does not require a semicolon! Nor does "while", "for", "foreach", "else", ...
Read your error and warning messages, and look at the lines they are talking about: it's a lot quicker to fix them yourself than to ask others!

I'd strongly recommend that you double click your Project...Properties in the "Solution Explorer" pane, select the "Build" tab, and set "Treat warnings as errors" to "All" - particularly when you are just starting. I have my project templates set to do that automatically as warnings are normally a good indicator that I mistyped something!
if(Label1 = "select * from cs100020 where countno=2 and status=3");


You don't put a semi-colon at the end, to compare things you use "==" not "=".

else (Label1="select * from cs100020 where countno=3 and status=3);


"else" doesn't have a condition in parenthesis as it is the condition used if no other matches. If you want to add a condition use "else if" rather than "else".
 
Share this answer
 

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