<ej:Grid ID="Grid1" AllowPaging="True"
EnableRowHover="true" AllowCellMerging="false" AllowReordering="false" Locale="en-US" AllowMultiSorting="false"
AllowSelection="True" Selectiontype="Single"
runat="server">
<Columns>
.
.
.
</Columns>
<ClientSideEvents ToolbarClick="onToolBarClick" />
<ToolbarSettings ShowToolbar="True" ToolbarItems=" excelExport,wordExport,pdfExport, add,edit,delete,update,cancel">
</ToolbarSettings>
</ej:Grid>
|
Public Partial Class GridFeatures
Inherits System.Web.UI.Page
Private order As New List(Of Orders)()
Protected Sub Page_Load(sender As Object, e As EventArgs)
BindDataSource()
End Sub
Private Sub BindDataSource()
Dim orderId As Integer = 10000
Dim empId As Integer = 0
Dim i As Integer = 1
While i < 9
order.Add(New Orders(orderId + 1, "VINET", empId + 1, 32.38, New DateTime(2014, 12, 25), "Reims"))
order.Add(New Orders(orderId + 2, "TOMSP", empId + 2, 11.61, New DateTime(2014, 12, 21), "Munster"))
order.Add(New Orders(orderId + 3, "ANATER", empId + 3, 45.34, New DateTime(2014, 10, 18), "Berlin"))
order.Add(New Orders(orderId + 4, "ALFKI", empId + 4, 37.28, New DateTime(2014, 11, 23), "Mexico"))
order.Add(New Orders(orderId + 5, "FRGYE", empId + 5, 67.0, New DateTime(2014, 5, 5), "Colchester"))
order.Add(New Orders(orderId + 6, "JGERT", empId + 6, 23.32, New DateTime(2014, 10, 18), "Newyork"))
orderId += 6
empId += 6
System.Math.Max(System.Threading.Interlocked.Increment(i),i - 1)
End While
Me.Grid1.DataSource = order
Me.Grid1.DataBind()
End Sub
<Serializable> _
Public Class Orders
Public Sub New()
End Sub
Public Sub New(orderId As Integer, customerId As String, empId As Integer, freight As Double, orderDate As DateTime, shipCity As String)
Me.OrderID = orderId
Me.CustomerID = customerId
Me.EmployeeID = empId
Me.Freight = freight
Me.OrderDate = orderDate
Me.ShipCity = shipCity
End Sub
Public Property OrderID() As Integer
Public Property CustomerID() As String
Public Property EmployeeID() As Integer
Public Property Freight() As Double
Public Property OrderDate() As DateTime
Public Property ShipCity() As String
End Class
Protected Sub FlatGrid_ServerExcelExporting(sender As Object, e As Syncfusion.JavaScript.Web.GridEventArgs)
Dim exp As New ExcelExport()
exp.Export(Grid1.Model, DirectCast(Grid1.DataSource, IEnumerable), "Export.xlsx", ExcelVersion.Excel2010, True, True, _
"flat-lime")
End Sub
Protected Sub FlatGrid_ServerWordExporting(sender As Object, e As Syncfusion.JavaScript.Web.GridEventArgs)
Dim exp As New WordExport()
exp.Export(Grid1.Model, DirectCast(Grid1.DataSource, IEnumerable), "Export.docx", True, True, "flat-lime")
End Sub
Protected Sub FlatGrid_ServerPdfExporting(sender As Object, e As Syncfusion.JavaScript.Web.GridEventArgs)
Dim exp As New PdfExport()
exp.Export(Grid1.Model, DirectCast(Grid1.DataSource, IEnumerable), "Export.pdf", True, True, "flat-lime")
End Sub
End Class
|
Hi,
with my SqlDataSource defined in aspx file :
<asp:SqlDataSource ID="SqlDataSourceOrdinateurs" runat="server" ConnectionString="<%$ ConnectionStrings:DefaultConnection %>" SelectCommand="PsListeOrdinateurDate" SelectCommandType="StoredProcedure">
<SelectParameters>
<asp:ControlParameter ControlID="DatePicker1" DbType="Date" Name="Date" PropertyName="Value" />
</SelectParameters>
</asp:SqlDataSource>
And in aspx.vb file :
Grid display correctly but now when i click on excel export button i get this :Private Sub BindDataSource()Grid1.DataSource = SqlDataSourceOrdinateursGrid1.DataBind()End Sub
L'exception System.InvalidCastException n'a pas été gérée par le code utilisateur
HResult=-2147467262
Message=Impossible d'effectuer un cast d'un objet de type 'System.Web.UI.WebControls.SqlDataSource' en type 'System.Collections.IEnumerable'.
Source=Parc
StackTrace:
à Parc.Ordinateurs.FlatGrid_ServerExcelExporting(Object sender, GridEventArgs e) dans D:\Dropbox (NGRI)\Visual Studio\Parc\Parc\Ordinateurs.aspx.vb:ligne 46
à Syncfusion.JavaScript.Web.Grid.PostBackEventHandler(String EventName, Dictionary`2 args)
à Syncfusion.JavaScript.Web.CommonDataBoundControl.RaisePostBackEvent(String EventArgument)
InnerException:
Partial Public Class GridFeatures
Inherits System.Web.UI.Page
Private dt As New DataTable
Protected Sub Page_Load(sender As Object, e As EventArgs)
BindDataSource()
End Sub
Private Sub BindDataSource()
Dim dt As New DataTable("Order")
Dim myConnection As New SqlConnection(ConfigurationManager.ConnectionStrings("NORTHWNDConnectionString").ToString())
dt = New DataTable("Order")
Dim cmd As New SqlCommand()
cmd.Connection = myConnection
cmd.CommandText = "select * from Orders"
cmd.CommandType = CommandType.Text
Dim da As New SqlDataAdapter()
da.SelectCommand = cmd
If myConnection.State = ConnectionState.Closed Then
myConnection.Open()
End If
da.Fill(dt)
Grid1.DataSource = dt
End Sub
<Serializable> _
Public Class Orders
Public Sub New()
End Sub
Public Sub New(orderId As Integer, customerId As String, empId As Integer)
Me.OrderID = orderId
Me.CustomerID = customerId
Me.EmployeeID = empId
End Sub
Public Property OrderID() As Integer
Public Property CustomerID() As String
Public Property EmployeeID() As Integer
End Class
Private Function ConvertToIenumerable(dataTable As DataTable) As IEnumerable(Of Orders)
Dim orders = New List(Of Orders)()
For Each row As DataRow In dataTable.Rows
Dim order As New Orders()
order.OrderID = Convert.ToInt32(row("OrderID"))
order.CustomerID = row("CustomerID").ToString()
order.EmployeeID = Convert.ToInt32(row("EmployeeID"))
orders.Add(order)
Next
Return orders.AsEnumerable()
End Function
Protected Sub FlatGrid_ServerExcelExporting(sender As Object, e As Syncfusion.JavaScript.Web.GridEventArgs)
Dim exp As New ExcelExport()
exp.Export(Grid1.Model, ConvertToIenumerable(Grid1.DataSource), "Export.xlsx", ExcelVersion.Excel2010, True, True, _
"flat-lime")
End Sub
Protected Sub FlatGrid_ServerWordExporting(sender As Object, e As Syncfusion.JavaScript.Web.GridEventArgs)
Dim exp As New WordExport()
exp.Export(Grid1.Model, ConvertToIenumerable(Grid1.DataSource), "Export.docx", True, True, "flat-lime")
End Sub
Protected Sub FlatGrid_ServerPdfExporting(sender As Object, e As Syncfusion.JavaScript.Web.GridEventArgs)
Dim exp As New PdfExport()
exp.Export(Grid1.Model, ConvertToIenumerable(Grid1.DataSource), "Export.pdf", True, True, "flat-lime")
End Sub
End Class |