Showing posts with label C#. Show all posts
Showing posts with label C#. Show all posts

Saturday, March 6, 2010

Import Excel Sheet into a .NET C# page

I got my idea from here
http://www.java2s.com/Code/ASP/ADO.net-Database/LoaddatafromExceldatasourceC.htm
It actually worked beautifully, I read it straight into a gridview now I can deal with the data normally

protected void Page_Load(object sender, EventArgs e)
{
string ConnectionString = @"Provider=Microsoft.Jet.OLEDB.4.0; Data Source=C:\Book1.xls; Extended Properties=""Excel 8.0;HDR=Yes"";";
string CommandText = "select * from [Sheet1$]";

OleDbConnection myConnection = new OleDbConnection(ConnectionString);
OleDbCommand myCommand = new OleDbCommand(CommandText, myConnection);

myConnection.Open();

GridView1.DataSource = myCommand.ExecuteReader(CommandBehavior.CloseConnection);
GridView1.DataBind();

myConnection.Close();
}

Tuesday, September 22, 2009

Convert HTML Form Elements to ASP.NET form elements

Here is my quick method for converting an HTML page to an ASPX page, handling the controls.
1. First I am going to add runat = "server" to the Form tag. I am also going to remove any function calls that were there previously since I will be replacing it with .NET code. I am removing the action and onsubmit elements from the tag.

Transform to


2. Next I am going to find all the text boxes:

Find
Replace with

If your tags are not arranged with the name following "text" you may need to modify it manually or be more specific with your find/replace

If you are closing the input tag, you will need to manually replace it with a closing
tag. Be careful because there are multiple types of inputs in your form, you do not want to replace all of them.
3. Next, I do the same find and replace with the submit button:

to
runat = "server" ID=
4. Translate your submit action into .NET code behind



EDIT:
The copy and pasting of HTML screwed up the entry I made. I will fix it later.