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

C# ( asp.net ) 2019 visual studio I have a dropdown option. If I choose "date"...
C# ( asp.net ) 2019 visual studio I have a dropdown option. If I choose "date" option, I get to enter list of dates like 02/08/1990, 06/14/1890 in (mm/dd/YYYY) format. How can I sort these dates in ascending order?. Can you provide me some code. Thank you
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 a new website using C# & ASP.Net in Visual Studio: 1. Create a web page...
Create a new website using C# & ASP.Net in Visual Studio: 1. Create a web page to access a database and display the data from a table by providing an SQL statement. Create the page with these requirements:     create label, textbox and button     the textbox will capture the SQL statement     the button will process the statement and display the results 2. Add necessary data access pages to your project. 3. Display the data in Gridview
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...
Code: please use in visual studio 2019 c++ (not java) In total you will write 6...
Code: please use in visual studio 2019 c++ (not java) In total you will write 6 functions: Functions : A ) addInts, returns int; input is two ints; Add the values of the two parameters and return the sum B) subInts , returns int; input is two ints; Subtract the values of the two parameters and return the difference C) multInts, returns int; input is two ints; multiple the values of the two parameters and return the product D) divInts,...
Subject- ( App Development for Web) ( language C#, software -visual studio) I have created a...
Subject- ( App Development for Web) ( language C#, software -visual studio) I have created a 'Calculator' named program in visual studio. This is the main console program(Program.cs) shown below. Then i have created a "CaculatorLibrary" named project by adding the project from FILE--->ADD--->NEW PROJECT. Then i selected library and selected classLibrary(.NETcore). The programs for both are given below. There are no errors in the program. Now the requirement is to build unit test project within this project that will...
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...
C++ Visual Studio 2019 Part A : Program Description: Write a program to generate a report...
C++ Visual Studio 2019 Part A : Program Description: Write a program to generate a report based on input received from a text file. Suppose the input text file student_grades.txt contains the student’s Last name , First name, SSN, Test1, Test2, Test3 and Test4. (25%) i.e. Alfalfa   Aloysius   123-45-6789 40.0    90.0   100.0    83.0 Generate the output Report File student_final.txt in the following format : LastName FirstName   SSN Test1   Test2   Test3   Test4 Average FinalGrade i.e. Alfalfa   Aloysius   123-45-6789 40.0    90.0   100.0   ...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT