Implementing the Date time picker in ASP.NET

Though we do not have a date time picker in ASP.net as an inbuilt control, it is pretty easy to implement. Let us see how.
1) Just add a text box, image button and a calendar control to your form.
2) Initially set the visibility of the calendar to false.
3) On the button click event, enable the calendar to select a date.
4) On selection change event of the calendar, populate the selected date to the text box and again set the visibility of the calendar to false.

Quiet simple, Right? 🙂 Just take a look of the images below to see the design and code.

Handeling the functionality of the custom columns created out of template field and Item template field in grid view

Customization of grid view elements is the foremost thing, we will be asked to do most of the times. Let us see how to do that through this blog.

The above figure will give you the functionality to be implemented:
1) The Grid view should contain the image buttons for edit, delete and submit
2) The Order creation date column’s values should get highlighted in green, if today is the order creation date and the value should be highlighted in red if the order creation date is some other previous days.

Customizing the Grid with image buttons
Design code

To achieve the above functionality, first configure the grid view with a data source. Now in order to add the image buttons to the grid, include the template field bound with the item template tag and place an image button with in the template field with the properties added as shown in the image(Click the link to view the image).

Now, in order to make use of the image buttons bound inside the item templates set the ‘CommandArgument’ property and ‘CommandName’ as shown in the highlighted box. This will help to fetch the primary key of the particular record to do database operations.

Enabling the ‘RowCommand’ and ‘RowDataBound’

In order to implement the logic for the image button’s click event and the date highlighting functionality, Go to the design page, i.r Form.aspx and go to the grid view’s properties window, in which select the ‘Events’ tab. Now double-click on the ‘RowDataBound’ and ‘RowCommand’ events that will take you to the code behind, i.e Form.aspx.cs where you will find the two methods to implement your logic.you can find the events tab of the grid view’s properties window as shown in the figure(Click the link to view the image below.)

Properties

Implementing the code logic
Code Behind

Under the ‘RowCommand’, you can implement the logic as shown in the image(Click the above link) to do your required functionality for the image button click as given in the Highlighted box. Here you need to use the command name in order to have multiple custom columns

In order to implement the highlighting functionality, go to the ‘RowDataBound’ method define the logic as shown in the image below.

Highlight code

Binding the dropdown values through code

This is something very basic and simple, most of the beginners like me encounters. You might wonder how to bind the list elements manually into the dropdown list instead binding the data source in C#.net. If you have ended up in the same, its is the right place to figure it out. Here I go,

protected void Page_Load(object sender, EventArgs e) //values are populated when the page is requested by the client
{
string[] names = {“Sharmili”,”Deepika”,”Rathinam”,”Anitha”}; //Get the dropdown list elements to be populated

foreach (string i in names) //when you use foreach, you need not bother about array index
{
DropDownList1.Items.Add(i);
}

//The other way to bind the values one by one is shown below
//DropDownList1.Items.Add(“Sharmili”);
//DropDownList1.Items.Add(“Deepika”);
}

Code logic to calculate the number of business dates between two dates

The code snippet, shown below will help you to calculate the number of business days between two dates in C#.

public int calc(DateTime today, DateTime delivery)

//day in which order is placed and expected delivery date are passed as parameters
{
int Bday = 0;
DateTime businessDay;
for (businessDay = today; businessDay <= delivery; businessDay=businessDay.AddDays(1))

//iterate from the current date to expected delivery date
{
if (businessDay.DayOfWeek.ToString() != “Saturday” && businessDay.DayOfWeek.ToString() != “Sunday”)
{
Bday++;

// increments the days if the present day is not a Saturday or a Sunday
}
}
return Bday;    //returns the number of business days starting from today
}

கற்பனை மறைந்ததடி!!!

கற்பனை மறைந்ததடி , என் கற்பனை மறைந்ததடி !
உன் மையிட்ட விழிகளை எழுதிய பேனாவில் கற்பனை மையும் மறைந்ததடி!

வார்த்தைகள் தீர்ந்ததடி , என் வார்த்தைகள் தீர்ந்ததடி!
உன் செவிதழின் அழகை கணிசுலையாய் சொன்ன வாயிலே வார்த்தைகள் தீர்ந்தடடி!

கனவுகள் முடிந்ததடி, என் கனவுகள் முடிந்ததடி!
உன் உருவத்தை கற்சிலையாய் வடிக்கவிருந்த இதயத்தின் கனவுகள் முடிந்ததடி!

பாலையாய் போனதடி, நீயின்றி பாலையாய் போனதடி!
சோலையாய் பூத்த இதயம் வறண்ட பாலையாய் போனதடி!

காரிருள் சூழ்நததடி, நீயின்றி காரிருள் சூழ்நததடி!
முழுமதியை சுற்றிவந்த உன் முகம் மறைந்த காரனத்தால் காரிருள் சூழ்நததடி!

வரட்சியில் காய்ந்ததடி, நீயின்றி வரட்சியில் காய்ந்தடடி!
மலர்போல அலர்ந்த மனம் நீருற்ற நீயின்றி வரட்சியில் காய்ந்ததடி!