hello to all,
i have write a code in asp.net to show and hide the div.
according to the value in the query string.
here is my code:

if (Request.QueryString["divid"] != null)
        {
            divid =Request.QueryString["divid"].ToString().Trim();
            if (divid == "watercalc")
            {
                watercalc.Style["display"] = "block";
                pregnancycalc.Style["display"] = "none";
                heartbeatcalc.Style["display"] = "none";
                fatcalc.Style["display"] = "none";
                heightcalc.Style["display"] = "none";

            }
            else if (divid == "pregnancycalc")
            {
                watercalc.Style["display"] = "none";
                pregnancycalc.Style["display"] = "block";
                heartbeatcalc.Style["display"] = "none";
                fatcalc.Style["display"] = "none";
                heightcalc.Style["display"] = "none";

            }
            else if (divid == "heartbeatcalc")
            {
                watercalc.Style["display"] = "none";
                pregnancycalc.Style["display"] = "none";
                heartbeatcalc.Style["display"] = "block";
                fatcalc.Style["display"] = "none";
                heightcalc.Style["display"] = "none";

            }
            else if (divid == "heightcalc")
            {
                watercalc.Style["display"] = "none";
                pregnancycalc.Style["display"] = "none";
                heartbeatcalc.Style["display"] = "none";
                fatcalc.Style["display"] = "none";
                heightcalc.Style["display"] = "block";

            }
            else if (divid == "fatcalc")
            {
                watercalc.Style["display"] = "none";
                pregnancycalc.Style["display"] = "none";
                heartbeatcalc.Style["display"] = "none";
                fatcalc.Style["display"] = "block";
                heightcalc.Style["display"] = "none";

            }
        }

now, i want to compress my code.
i know i can do it with the use of array but i am unable to do this.
anyone could help me?please......

Are you trying to simplify your code? If that is the case, I would recommend something along the lines of setting all the values to a default of "none" as that is most often the case, and changing only the values that need it. See below:

watercalc.Style["display"] = "none";
                pregnancycalc.Style["display"] = "none";
                heartbeatcalc.Style["display"] = "none";
                fatcalc.Style["display"] = "none";
                heightcalc.Style["display"] = "none";

and then doing the

divid =Request.QueryString["divid"].ToString().Trim();

after that you can have the if else statements followed by one line setting the necessary item to "block", removing the repetition and extra brackets should cut down the lines of code by half or so.

Not sure if this is what you were actually looking for, but that's how I understood the question....

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.