C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Reviews   Communities   Interview   Jobs   Projects   Training   Your Ad Here    
Silverlight Games | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Polls | Revenue Sharing | Lobby | Gift Shop |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...






Resources » Code Snippets » ASP.NET GridView »

Populating the data copied from Excel


Posted Date: 12 Mar 2009    Resource Type: Code Snippets    Category: ASP.NET GridView
Author: ShankarMember Level: Diamond    
Rating: 1 out of 5Points: 12



Fetching copied data from excel file and populating the Gridview
---


We can copy the data from the Excel file.We can then paste the data into agridview using the code below.

The code will validate whether the data is available in the clipboard,and then validates that it is a comma seperated value.
This then populates the data into datarow and datatable.
Then assigns the datasource to the gridview "dgResource"



string[] langResourcePhrases;
DataTable dtResource;

if ((Clipboard.GetText().ToString() != null) && (Clipboard.GetText().ToString() != string.Empty))
{
DataRow drRow;
dsResource = new DataSet("Resource");
IDataObject xlobj;
string copyLines = "";
xlobj = Clipboard.GetDataObject();
if ((System.IO.MemoryStream)xlobj.GetData("csv") != null)
{
StreamReader xlStream = new StreamReader((System.IO.MemoryStream)xlobj.GetData("csv"));

while (!(xlStream.EndOfStream))
{
copyLines = xlStream.ReadLine();
if (copyLines != null && copyLines != string.Empty && copyLines != "\0")
{
drRow = dtResource.NewRow();
langResourcePhrases = copyLines.Split(',');
drRow[0] = langResourcePhrases[0].ToString();
drRow[1] = langResourcePhrases[1].ToString();
dtResource.Rows.Add(drRow);
}
}
dgResource.DataSource = dtResource




Responses

Author: Miss Meetu Choudhary    12 Mar 2009Member Level: Diamond   Points : 0
Good One Keep It UP...

Thanks and Regards
Meetu Choudhary


Feedbacks      
Popular Tags   What are tags ?   Search Tags  
Sign In to add tags.
IDataObject  .  GetDataObject  .  GetData  .  Csv  .  Clipboard  .  

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: Sorting two ways in gridview
Previous Resource: Downloading files from Gridview
Return to Discussion Resource Index
Post New Resource
Category: ASP.NET GridView


Post resources and earn money!
 
More Resources



dotNet Slackers

About Us    Contact Us    Privacy Policy    Terms Of Use