Click here to Skip to main content
15,894,017 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Background: About 4 weeks C#, please bear with me. I have a drop down box where users update the status of a project as either Active or Inactive.

I have the following methods that create and assign values to my dropdown list:
public class CommonSVC
    {
        #region Fill Item Status
        public void FillItemStatus(DropDownList uxStatusDdl, bool blankEntry, string blankEntryText, bool includeBothListItem)
        {
            if (includeBothListItem)
            {
                uxStatusDdl.Items.Add(new ListItem("Both", "-1"));
            }
            uxStatusDdl.Items.Add(new ListItem("Active", "0"));
            uxStatusDdl.Items.Add(new ListItem("Inactive", "1"));

            FillControl.AddBlankAndAllValues(uxStatusDdl, false, "", blankEntry, blankEntryText);
        }
        #endregion

        #region Fill Yes No
        public void FillYesNo(DropDownList ddl, bool blankEntry, string blankEntryText, bool includeBothListItem)
        {
            if (includeBothListItem)
            {
                ddl.Items.Add(new ListItem("Both", "-1"));
            }
            ddl.Items.Add(new ListItem("Yes", "1"));
            ddl.Items.Add(new ListItem("No", "0"));
            FillControl.AddBlankAndAllValues(ddl, false, "", blankEntry, blankEntryText);        
        }
        #endregion 

        #region Get Yes No Value By DDL Value
        public static string GetYesNoValueByDDLValue(string ddlValue)
        { 
            switch (ddlValue)
            {
                case "0":
                   return "0";
                case "1":
                    return "1";
                case "-1":
                    return "0,1";
            default:
                    return string.Empty;
            }
        }
        #endregion

The actual method that invokes a change to my project status is:
VB
: accountTrackersvc.UpdateConnectionType(DataConverter.StringToInteger(ViewState["ConnectionTypeID"].ToString()),
uxConnectionTypeDescTxt.Text.Trim(),
Enums.GetIsDisabledByItemStatusValue(SafeValueAccessor.GetControlValue(uxStatusDdl)), /* This line updates project status */
CommonSVC.GetUserInfoFormattedFromSession());


I've generated a method stub for the GetIsDisabledByItemStatusValue() method and made some changes as well, so far this is what I've got:

C#
public static object GetIsDisabledByItemStatusValue(string p)
       {
           bool ActiveIndicator = true;
           if (ActiveIndicator) //Then I want to set the status to Active
           {
               CommonSVC.GetYesNoValueByDDLValue(string ddlValue) // error here reads: invalid expression term

           }

           return p;
       }
       #endregion


You'll notice that the method of interest is within an enum class, I'm working within a pre-built template and thus am confined to work with what I have already there. There are no errors in the top 2 code blocks above. My question is: how would I implement a method in the enums class that would connect the 2 blocks of code from my CommonSVC class and the invocation class?
Posted
Updated 8-Jul-15 5:36am
v2
Comments
Andy Lanng 8-Jul-15 11:40am    
you can't declare a variable in the method parameters
CommonSVC.GetYesNoValueByDDLValue(/*This is were the method params go*/)

Was that the issue or is it there for demonstration only?
Member 11820531 8-Jul-15 11:47am    
The issue is in my last block of code. What I was trying to do was pass the same parameter values that were passed when the method was initially created. The commonsvc class holds the 1st and original method using the same parameters.
Andy Lanng 8-Jul-15 11:56am    
Ok - hold up. Your using some terms incorrectly and it's throwing me off, but I get that your new so I'll try to pick it apart:

"pass the same parameter values" ok - got that
"when the method was initially created" - do you mean "when it was first used / called? If so, where was it first called. Can you post the code?

I think I get your confusion. A method does not "hold" any values after it completes. You can hold on to these values in different "scopes". Try to explain your intention further if you can.

1 solution

The problem is here:
C#
CommonSVC.GetYesNoValueByDDLValue(string ddlValue)
And (if we ignore the missing semicolon), the problem is that you want to pass the GetIsDisabledByItemStatusValue parameter to the GetYesNoValueByDDLValue method and save teh result. So try:
C#
string ddlValue = CommonSVC.GetYesNoValueByDDLValue(p);
And your error message should go away.

But please, do yourself a favour, and don't use a new region for each method. Use regions to group related methods by all means, but methods just need an XML comment header: C# Documenting and Commenting[^] If you do that, they are easy to see, and Visual Studio Intelisense will pick up on it and help you when you try to use the method.
If you are using regions so you can "hide" method details, you don't need to - have a look at the Visual Studio Outlining feature: https://msdn.microsoft.com/en-us/library/td6a5x4s.aspx[^] - does the same thing, but a lot more flexibly.
 
Share this answer
 
Comments
Member 11820531 8-Jul-15 11:58am    
Your solution worked. Thank you, I appreciate your feedback. I'll also be sure to look into the links you've included.
OriginalGriff 8-Jul-15 12:06pm    
You're welcome!
Andy Lanng 8-Jul-15 12:07pm    
5'ed for interpreting correctly. I just couldn't quite see it #^_^#

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