Question

In: Computer Science

C# ( asp.net ) 2019 Visual Studio I have a dropdown where you can select (...

C# ( asp.net ) 2019 Visual Studio

I have a dropdown where you can select ( integer, string, date )

After selecting the desired dropdown option, user can input a list of inputs. For example; for integer: 2,5,7,9,1,3,4

And then , I have a 'sort' button

Can you please help me with the code behind for sorting them( For integer, string, and date )

Thank you.

Solutions

Expert Solution

In visual studio web application is created with name "SortInputs".Below are the details.

Default.aspx :

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="SortInputs.Default" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<%-- title for web page --%>
<title>Sorting application</title>
</head>
<body>
<form id="form1" runat="server">
<%-- drop down list for data types --%>
Select Data Type :<asp:DropDownList ID="ddlDataTypes" runat="server" AutoPostBack="True" OnSelectedIndexChanged="ddlDataTypes_SelectedIndexChanged">
<asp:ListItem Selected="True">--Select Data type--</asp:ListItem>
<asp:ListItem>Integer</asp:ListItem>
<asp:ListItem>String</asp:ListItem>
<asp:ListItem>Date</asp:ListItem>
</asp:DropDownList>
<br />
<br />
<%-- label to display list header --%>
<asp:Label ID="lblList" runat="server"></asp:Label>
&nbsp;
<%-- textbox for input lists --%>
<asp:TextBox runat="server" ID="txtList" Visible="False"></asp:TextBox>
&nbsp;
<%-- button to sort inputs --%>
<asp:Button runat="server" Text="Sort" ID="btnSort" OnClick="btnSort_Click" Visible="False" />
<br />
<br />
<%-- label to display sorted inputs --%>
<asp:Label runat="server" ID="lblHeader"></asp:Label>

</form>
</body>
</html>

******************************

Default.aspx.cs :

//namespace
using System;
//application namespace
namespace SortInputs
{
public partial class Default : System.Web.UI.Page
{
//When data type from dropdown list is selected
protected void ddlDataTypes_SelectedIndexChanged(object sender, EventArgs e)
{
if (ddlDataTypes.SelectedIndex == 0)
{
//if defaule option is selected
lblHeader.Text = "Select valid data type";
}
else if (ddlDataTypes.SelectedIndex == 1)
{
//if integer data type is selected then
lblList.Text = "Enter Integers : ";//set text on the label
txtList.Visible = true;//show the textbox
btnSort.Visible = true;//show sort button

}
else if (ddlDataTypes.SelectedIndex == 2)
{
//if string data type is selected then
lblList.Text = "Enter Strings : ";//set text on the label
txtList.Visible = true;//show the textbox
btnSort.Visible = true;//show sort button

}
else if (ddlDataTypes.SelectedIndex == 3)
{
//if date data type is selected then
lblList.Text = "Enter Dates (dd/mm/yyyy) : ";//set text on the label
txtList.Visible = true;//show the textbox
btnSort.Visible = true;//show sort button
  
}
}
//sort button click
protected void btnSort_Click(object sender, EventArgs e)
{
//taking input entered by user in the textbox
string inputList = txtList.Text;
//checking which data type is selected
if(ddlDataTypes.SelectedIndex == 1)
{
//if data type is integer
//call method to sort the integers
sortIntegers(inputList);
}
//checking which data type is selected
else if (ddlDataTypes.SelectedIndex == 2)
{
//if data type is string
//call method to sort the strings
sortStrings(inputList);
}
//checking which data type is selected
else if (ddlDataTypes.SelectedIndex == 3)
{
//if data type is date
//call method to sort the dates
sortDates(inputList);
}

}
//method to sort integers
public void sortIntegers(string intList)
{
//spliting intList based on comma (,)
string[] intArr = intList.Split(',');   
int[] intSortArray = new int[intArr.Length]; //declaring integer array to hold integers
//using for loop to loop through each array element and converting each element in the integer
for (int j= 0;j < intArr.Length; j++)
{
intSortArray[j] = int.Parse(intArr[j]);//convert each array element to integer
}
//calling Array Sort() method to sort the integer array
Array.Sort(intSortArray);
string integers = "";//display each number on the lable
//using for loop display each array in the label
for (int j = 0; j < intSortArray.Length; j++)
{
if (j != intSortArray.Length - 1)
{
integers += intSortArray[j] + ",";
}
else
{
integers += intSortArray[j];
}

}
lblHeader.Text =integers;//display integers
}
//method to Sort Strings
public void sortStrings(string stringList)
{
string[] sortedStrings = stringList.Split(',');//split input based on ,
//sort the array using Array.Sort() method
Array.Sort(sortedStrings);
//concate sorted strings from array and display
string strings = "";
for (int i = 0; i < sortedStrings.Length; i++)
{
if (i != sortedStrings.Length - 1)
{
strings += sortedStrings[i] + ",";
}
else
{
strings += sortedStrings[i];
}

}
lblHeader.Text = strings;//display strings
}

//method to Sort Dates
public void sortDates(string dateList)
{
string[] dateArray = dateList.Split(',');//spliting input based on ,
//declaring date array to hold the dates
DateTime[] SortedDates = new DateTime[dateArray.Length];
//using for loop to converting each element of the array in the date
for (int i = 0; i < dateArray.Length; i++)
{
string[] dmy = dateArray[i].Split('/');//split array element on '/'
//usin above array form a date and store in the array
SortedDates[i] = new DateTime(int.Parse(dmy[2]), int.Parse(dmy[1]), int.Parse(dmy[0]));
}
Array.Sort(SortedDates);//sort the array using Array.Sort()
string dates = "";//variable to concate each date
for (int i = 0; i < SortedDates.Length; i++)
{
int y = SortedDates[i].Year;//get year from the date
int m = SortedDates[i].Month;//get month from the date
int d = SortedDates[i].Day;//get day from the date
if (i != dateArray.Length - 1)
{
//concate day,month and year to form a date
dates += String.Format("{0}/{1}/{2}", d, m, y) + ",";
}
else
{
dates += String.Format("{0}/{1}/{2}", d, m, y);
}

}
lblHeader.Text = dates;//display dates
}

}
}

====================================

Screen 1:Default.aspx

Screen 2:Sorted integers

Screen 3:Sorted strings

Screen 4:Sorted dates


Related Solutions

Create a C++ project in visual studio. You can use the C++ project that I uploaded...
Create a C++ project in visual studio. You can use the C++ project that I uploaded to complete this project. 1. Write a function that will accept two integer matrices A and B by reference parameters, and two integers i and j as a value parameter. The function will return an integer m, which is the (i,j)-th coefficient of matrix denoted by A*B (multiplication of A and B). For example, if M = A*B, the function will return m, which...
Create an ASP.Net Website using Visual Studio with C#: Create a simple calculator that has 3...
Create an ASP.Net Website using Visual Studio with C#: Create a simple calculator that has 3 text boxes: 2 of them to enter numbers, the 3rd one displays the results Create 4 buttons to add, subtract, multiply, and divide Prevent the user from entering text in the number fields Display a message indicating “cannot divide by” when the user click “/” and there is a zero the in the second box Create two additional buttons: - One to store data...
Create an ASP.Net Website using Visual Studio with Visual Basic.Net: Create a simple calculator that has...
Create an ASP.Net Website using Visual Studio with Visual Basic.Net: Create a simple calculator that has 3 text boxes: 2 of them to enter numbers, the 3rd one displays the results Create 4 buttons to add, subtract, multiply, and divide Prevent the user from entering text in the number fields Display a message indicating “cannot divide by” when the user click “/” and there is a zero the in the second box Create two additional buttons: - One to store...
USING VISUAL STUDIO 2017, LANGUAGE VISUAL C# I have struggled on this program for quite some...
USING VISUAL STUDIO 2017, LANGUAGE VISUAL C# I have struggled on this program for quite some time and still can't quite figure it out. I'm creating an app that has 2 textboxes, 1 for inputting customer name, and the second for entering the number of tickets the customer wants to purchase. There are 3 listboxes, the first with the days of the week, the second with 4 different theaters, and the third listbox is to display the customer name, number...
ONLY USE VISUAL STUDIO (NO JAVA CODING) VISUAL STUDIO -> C# -> CONSOLE APPLICATION In this...
ONLY USE VISUAL STUDIO (NO JAVA CODING) VISUAL STUDIO -> C# -> CONSOLE APPLICATION In this part of the assignment, you are required to create a C# Console Application project. The project name should be A3<FirstName><LastName>P2. For example, a student with first name John and Last name Smith would name the project A1JohnSmithP2. Write a C# (console) program to calculate the number of shipping labels that can be printed on a sheet of paper. This program will use a menu...
I need a few unit tests done on my SelectionSort program in Visual Studio 2019 with...
I need a few unit tests done on my SelectionSort program in Visual Studio 2019 with MSTest. My program is below. I just need screen shots of the unit test code in Visual Studio 2019 with MSTest. Please and thank you. so easentially I need someone to write some unit tests with my program in MSTest visual studio 2019. Then I need the unit tests supplied as answers. using System; namespace SelectionSortAlgorithm { public class SelectionSort { public static void...
I need the code for following in C++ working for Visual studio please. Thanks Use a...
I need the code for following in C++ working for Visual studio please. Thanks Use a Struct to create a structure for a Player. The Player will have the following data that it needs maintain: Struct Player int health int level string playerName double gameComplete bool isGodMode Create the 2 functions that will do the following: 1) initialize(string aPlayerName) which takes in a playername string and creates a Player struct health= 100 level= 1 playerName = aPlayerName gameComplete = 0...
how can i make in visual studio a farm wide solution for SP 2013. a marquee...
how can i make in visual studio a farm wide solution for SP 2013. a marquee that conects to the announcement list amd shows this message in my whole farm (or similar). Thank You in advance
Programming Language: C# CheckingAccount class You will implement the CheckingAccount Class in Visual Studio. This is...
Programming Language: C# CheckingAccount class You will implement the CheckingAccount Class in Visual Studio. This is a sub class is derived from the Account class and implements the ITransaction interface. There are two class variables i.e. variables that are shared but all the objects of this class. A short description of the class members is given below: CheckingAccount Class Fields $- COST_PER_TRANSACTION = 0.05 : double $- INTEREST_RATE = 0.005 : double - hasOverdraft: bool Methods + «Constructor» CheckingAccount(balance =...
In Visual Studio in C#, you will create a simple calculator that performs addition, subtraction, multiplication,...
In Visual Studio in C#, you will create a simple calculator that performs addition, subtraction, multiplication, and division. Your program should request a numerical input from the user, followed by the operation to be performed, and the second number to complete the equation. The result should be displayed to the user after each equation is performed. For example, if the user performs 3+3, the program should display 6 as the result. The program should continue running so the user can...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT