Click here to Skip to main content
15,913,722 members
Home / Discussions / ASP.NET
   

ASP.NET

 
GeneralRe: How do i pass the SelectedValue/Index of a DropDownList in a GridViews EditItem Template to a Control Parameter? Pin
minhpc_bk1-Feb-07 18:44
minhpc_bk1-Feb-07 18:44 
QuestionReporting Problem Pin
Sarfaraj Ahmed1-Feb-07 1:15
Sarfaraj Ahmed1-Feb-07 1:15 
AnswerRe: Reporting Problem Pin
Sandeep Akhare1-Feb-07 2:58
Sandeep Akhare1-Feb-07 2:58 
GeneralRe: Reporting Problem Pin
Sarfaraj Ahmed2-Feb-07 1:40
Sarfaraj Ahmed2-Feb-07 1:40 
GeneralRe: Reporting Problem Pin
Sandeep Akhare2-Feb-07 2:03
Sandeep Akhare2-Feb-07 2:03 
GeneralRe: Reporting Problem Pin
Sarfaraj Ahmed2-Feb-07 4:03
Sarfaraj Ahmed2-Feb-07 4:03 
Questionhow to import data from an excel to a datagrid Pin
gauthee1-Feb-07 1:06
gauthee1-Feb-07 1:06 
AnswerRe: how to import data from an excel to a datagrid Pin
Parwej Ahamad1-Feb-07 1:18
professionalParwej Ahamad1-Feb-07 1:18 
.NET Classes used :
System.Data.DataSet
System.Data.OleDb.OleDbDataAdapter
System.Data.OleDb.
System.IO.StringWriter
System.Web.UI.HtmlTextWriter
This application uses a FileField (UploadFile)(HTML control) , One label (lblMessage), Button (btnSubmit), Button (btnExportToExcel), DataGrid (DataGrid1), This also explains how to upload a file.

Imports System
Imports System.Data
Imports System.Data.OleDb
Imports System.IO

Code :

Private Sub btnSubmit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSubmit.Click
Dim intFileNameLength As Integer
Dim strFileNamePath As String
Dim strFileNameOnly As String

If Not (UploadFile.PostedFile Is Nothing) Then
strFileNamePath = UploadFile.PostedFile.FileName

intFileNameLength = InStr(1, StrReverse(strFileNamePath), "\")

strFileNameOnly = Mid(strFileNamePath, (Len(strFileNamePath) - intFileNameLength) + 2)
Dim paths = Server.MapPath("/excelreading/")

paths = paths & "Excel/"

'If File.Exists(paths & strFileNameOnly) Then
'lblMessage.Text = "Image of Similar name already Exist,Choose other name"
'Else
If UploadFile.PostedFile.ContentLength > 40000 Then
lblMessage.Text = "The Size of file is greater than 4 MB"
ElseIf strFileNameOnly = "" Then
Exit Sub
Else
strFileNameOnly = Session("AdminID") & "-" & Session("Acountry") & "-" & Format(Date.Today, "mm-dd-yyyy").Replace("/", "-") & ".xls"
UploadFile.PostedFile.SaveAs(paths & strFileNameOnly)
lblMessage.Text = "File Upload Success."
Session("Img") = strFileNameOnly
End If
End If
'End If

Dim myDataset As New DataSet()
Dim strConn As String = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & Server.MapPath("/excelreading/") & "excel/" & strFileNameOnly & ";" & _
"Extended Properties=Excel 8.0;"

''You must use the $ after the object you reference in the spreadsheet
Dim myData As New OleDbDataAdapter("SELECT * FROM [Sheet1$]", strConn)
myData.TableMappings.Add("Table", "ExcelTest")
myData.Fill(myDataset)

DataGrid1.DataSource = myDataset.Tables(0).DefaultView
DataGrid1.DataBind()
End Sub

Private Sub btnExportToExcel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExportToExcel.Click
' Set the content type to Excel.
Response.ContentType = "application/vnd.ms-excel"
' Remove the charset from the Content-Type header.
Response.Charset = ""
' Turn off the view state.
Me.EnableViewState = False

Dim tw As New System.IO.StringWriter()
Dim hw As New System.Web.UI.HtmlTextWriter(tw)

' Get the HTML for the control.
DataGrid1.RenderControl(hw)
' Write the HTML back to the browser.
Response.Write(tw.ToString())
' End the response.
Response.End()
lblMessage.Text = "For any more information , feel free to contact ...!!!"
End Sub

ref : http://www.dotnetspider.com/kb/Article361.aspx

Parwej Back...............DON of Developer.......
Parwej Ahamad
g_parwez@rediffmail.com

AnswerRe: how to import data from an excel to a datagrid Pin
Sandeep Akhare1-Feb-07 3:09
Sandeep Akhare1-Feb-07 3:09 
GeneralRe: how to import data from an excel to a datagrid Pin
gauthee1-Feb-07 23:08
gauthee1-Feb-07 23:08 
GeneralRe: how to import data from an excel to a datagrid Pin
Sandeep Akhare2-Feb-07 2:06
Sandeep Akhare2-Feb-07 2:06 
GeneralRe: how to import data from an excel to a datagrid Pin
Sandeep Akhare2-Feb-07 2:15
Sandeep Akhare2-Feb-07 2:15 
QuestionWhy OleDbCommand call oracle9i user function success,but OleDbCommand call failed. Pin
Old Gun1-Feb-07 0:56
Old Gun1-Feb-07 0:56 
QuestionUser Control Pin
aaraaayen1-Feb-07 0:11
aaraaayen1-Feb-07 0:11 
AnswerRe: User Control Pin
blue_arc1-Feb-07 1:48
blue_arc1-Feb-07 1:48 
AnswerRe: User Control Pin
Sandeep Akhare1-Feb-07 3:01
Sandeep Akhare1-Feb-07 3:01 
AnswerRe: User Control Pin
DavidNohejl1-Feb-07 11:35
DavidNohejl1-Feb-07 11:35 
QuestionInterview Material Pin
rrcc31-Jan-07 23:08
rrcc31-Jan-07 23:08 
AnswerRe: Interview Material Pin
rrcc31-Jan-07 23:35
rrcc31-Jan-07 23:35 
AnswerRe: Interview Material Pin
_AK_31-Jan-07 23:44
_AK_31-Jan-07 23:44 
Questioninfo abt whiteboard Pin
Sebastian T Xavier31-Jan-07 22:55
Sebastian T Xavier31-Jan-07 22:55 
Questionproblem with datagrid-paging Pin
sanaziuse31-Jan-07 22:53
sanaziuse31-Jan-07 22:53 
AnswerRe: problem with datagrid-paging Pin
varshavmane31-Jan-07 22:56
varshavmane31-Jan-07 22:56 
GeneralRe: problem with datagrid-paging Pin
sanaziuse31-Jan-07 23:23
sanaziuse31-Jan-07 23:23 
GeneralRe: problem with datagrid-paging Pin
varshavmane31-Jan-07 23:48
varshavmane31-Jan-07 23:48 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.