Skip to main content
I try to read, bind data from K2DataGrid, through the properties ThisDataSet or DataSource in to typed DataSet and I get error: 'Specified cast is not valid'.
K2DataGrid is bind to K2 XML field, who has the same shema like typed DataSet to witch I want to bind data. Shema was generated from VS.NET. I can save data from K2 Smart Page but on the next page I can't read this data in the code, othervise the data are shown in UI.
Thanks
Here is an example that worked for me:

In your global.asax file on session start I read data from a xml file


Sub Session_Start(ByVal sender As Object, ByVal e As EventArgs)
' Fires when the session is started

Dim DS As New DataSet
Dim FS As FileStream

FS = New FileStream(Server.MapPath("Products.xml"), FileMode.Open, FileAccess.Read)
Dim Reader As StreamReader
Reader = New StreamReader(FS)
DS.ReadXml(Reader)
FS.Close()

Dim View As DataView
View = New DataView(DS.Tables(0))
Application("Source") = View

End Sub


On the Page load I do the following:


Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

Dim lngCount As Long

Dim Source As DataView = Application("Source")


If Not Page.IsPostBack Then

If Me.Page.Session("Source") Is Nothing Then
Me.Page.Session("Source") = K2DG.DataSource
End If

txtRecordcount.Text = 0

If Not Me.Page.Session("Source") Is Nothing Then
K2DG.DataSource = Me.Page.Session("Source")

lngCount = K2DG.DataSource.Table.Rows.Count

txtRecordcount.Text = lngCount

K2DG.DataBind()
End If

End If

End Sub


Take note that the property "AutoGenerateColumns" must be False in the K2DataGrid.
I find walk around. I read XML trough K2TextBox and than parse it to typed DataSet.
Thanks any way

Reply