Tuesday, April 28, 2009

Most Valuable Member : DotnetSpider.com

Today I have received The Most Valuable Member award from the DotnetSpider team, I am active on Dotnetspider.com forum from last 4 years.

Recently they introduced the MVM award for the best and quality contributors, I am very happy to receive this.

You can find the post at DotnetSpider MVMs and my profile in dotnetspider at My Profile

I am also happy for other members who got this award as this is prestigious to us.

Congratulations to all the Winners.

I would like to take this opportunity to thank each and every member in the forum.

Also I would like to thank editors, Raghav and Tony for your support towards me all the time.

Cheers,

Satish.

Thursday, April 23, 2009

Creating Dynamic Controls, and Preserve them for alternate Page Loads : ASP.NET

Normally when you create a control dynamically means at runtime, on the next page load you will loose that control, that control will be no longer exists, in this example I am try to explain how we can store that controls and get them back.

Create a Web Application and Add one button to it.
In the page load add following code, in the following code I am creating a object of Control Collection and keeping it in the Session.

image

Now Doble click on button1 and add following code in Button1_Click event.
Here in this code I am storing all the controls created into control collection and saving into session.

image

now we are ready with code just build, run and test.

Tags: Creating Dynamic controls, ASP.NET, C#, Preserve the Dynamic controls

Monday, April 20, 2009

Saving, Retrieving Data in Smart Device Applications

In this example I am try to use SQL Compact Edition with Smart Device Applications.

We can store data and update the data in the device using SQL CE, so lets start building a example.

Create SmartDeviceProject and add 2 Forms to it, please design the Form1 & Form2 as displayed in the Screen shot.




Now lets create a SQL CE database file, for that please right click on the project add new file and select Database file and name it as Employees.sdf



After adding the database file, create a table with following fields.
ID int
Name nVarchar
City nVarchar
Designation nVarchar



Now we are ready with design part lets write some code to insert data into table.

Now double click on the Add button and add following code, in the following code we are creating SQLCeConncetion object and SQLCeCommand Object to insert the data into the .sdf file, it is almost similar how we insert data into normal SQL Server database, normally our database file will be saved on the device where the application is installed so I have taken the path of the .sdf and creating a connection.

Double click on the View button and create a object for Form2 where will show all the employees details.




Now open the Form2 and add grid and one button as shown in the screen shot above, in Form2_Load event write the code to fill the datagrid, double click on back button and write a code to go back to Form1



Now we are ready with our code let built, run and Test

Saturday, April 11, 2009

Implementing Tabs using MultiView Control : ASP.NET

Using MultiView control in ASP.NET we can achieve tabs in a web page, now in this example I am going to explain how we can create tabs using MulitView control

Create a web application and add a Table control with 1 row and 3 columns and a MultiView control with 3 views, you can refer below screen shot

Here we are adding 3 cells using table control and each cell will have a link button which acts as Tab

image

We need to set ActiveViewIndex property of a MultiView control to see particular tab for that initially in Page_Load we set ActiveViewIndex to 0 and on clicking every link we will call TabChange event to show the particular tab, in the below code we identify which link button is clicked and based that we will change the ActiveViewIndex to show the contents

image

Now we are ready with out code, just build, run and test

Hope this helps

Tags : Tab control in ASP.NET, MulitView control, Satish Kumar J

Friday, April 10, 2009

Save Images in Access Database : ASP.NET

Using OLE Object we can save images in Access Database, in this example we will select a image and save that image in Access database using ASP.NET.

First we will start creating a table in access database.

Create a table ImageTable with following fields

  1. ID    AutoNumber (Primary Key)
  2. ImageName   Text
  3. ImageValue OLE Object

Now create a WebApplication and add following controls on the Web Form

  1. Upload Control
  2. Button for uploading image and saving into database
  3. DropdownList for listing all the images in Dabase Table
  4. Button for saving the image into a folder
  5. Image to show the image save on the disk

html

Initially we will fetch the image names which are already saved in the table and show in the drop down list,  for that use Page_Load method and insert following code

Page_Load

now double click on upload image button and add following code, in following code we are just reading the image into stream of bytes and we are storing into the database

UploadImage

To resave the image on to the disk we will use following code, once we save image from database to disk we will show that image in image1 control.

SaveImage

now we are ready with our code just build, run and test

hope this helps

Tags: Save images in Access Database, ASP.NET, Save images in Database

Wednesday, April 8, 2009

IsNumeric in C#

In C#.NET we don’t have IsNumeric function; to achieve same functionality as IsNumeric in C# we can make use of Double.TryParse. Please find following example how we can achieve this

double db;
string strInput = "SomeValue";
if (double.TryParse(strInput, out db))
{
Response.Write(db.ToString());
}
else
{
Response.Write("Not a number");
}

Hope this helps.
Tag: IsNumeric in C#, .NET

Monday, April 6, 2009

Get All Sundays in a Year

Following function will return all the Sundays in a specified Year.

/// /// This function will return all the dates of sundays in a Year
/// for example if you pass if year is 2009
/// it will return all the dates of sundays in the year in form of list
///

/// Year
/// List all dates of sundays in form of list string
public List getAllWeekDates(int Year)
{
List strDates = new List();
for (int month = 1; month <= 12; month++)
{
DateTime dt = new DateTime(Year, month, 1);
int firstSundayOfMonth = (int)dt.DayOfWeek;
if (firstSundayOfMonth != 0)
{
dt = dt.AddDays((6 - firstSundayOfMonth) + 1);
}
while (dt.Month == month)
{
strDates.Add(dt.ToString("dd/MMM/yyyy"));
dt = dt.AddDays(7);
}
}
return strDates;
}

Testing above function

List allSundays = getAllWeekDates(DateTime.Now.Year);
DropDownList1.DataSource = allSundays;
DropDownList1.DataBind();

Hope this helps

Tags: .NET, C# DateTime, All Sundays in a Year

Thursday, April 2, 2009

Export to Excel from DataGridView

Here I am explaining, how we can generate Excel file from the DataGridView.

Here I am using DataTable.WriteXML method generate the excel file.

Create a Window Forms Application and on the Form1 add following controls

  1. DataGridView
  2. Button and rename to “Generate Excel File”
  3. FolderBrowserControl

image

Now add following code in Form1_Load Event, in following code I am creating a DataAdapter to get the data from data base and assigning DataGridView’s DataSource.

image

And add following code in Button1_Click event, In following code I getting back the DataSource and converting it into DataTable and using DataTable’s WriteXML method I am generating Excel File.

image

Now we are ready with our code just Build, Run and Test

image

Hope This Helps.

Tags: DataGridView, Excel, Export, C#, windows