Free Support Forum - aspose.com

Aspose.Grid Sizing and DataBind

I have an eval version of the latest version of Aspose.Grid (version 2.0). When I perform a Databind to a SQL Query it appears to bind (has the correct number of rows in the grid) but no data is displayed.

ssql is a properly formated sql query statement...

sqlcommand1.CommandText = ssql

sqlcommand1.CommandType = System.Data.CommandType.Text

Dim ps = New DataSet

Dim sadaptor = New SqlClient.SqlDataAdapter(sqlcommand1)

sadaptor.Fill(ps)

Dim sheet As WebWorksheet = GridWeb1.WebWorksheets(0)

sheet.Cells.Clear()

sheet.EnableCreateBindColumnHeader = True

sheet.BindStartRow = 2

sheet.Cells.Merge(0, 0, 2, 50)

sheet.DataSource = ps

sheet.DataBind()

Secondly, I want to size the grid to a portion of the form, but using the

GridWeb1.Height = New Unit(60, UnitType.Percentage)

GridWeb1.Width = New Unit(75, UnitType.Percentage)

has no impact on its size. I have tried using other UnitTypes as well with no luck.

Thank you for your help.

Ivan

Hi,

Thanks for considering Aspose.

1). Well, I am not sure about your data source table(s). Please make sure that your source table(s) has data in it. By the way, could you try to add the line to your code if it works:

e.g..,

sheet.EnableCreateBindColumnHeader = True

sheet.BindStartRow = 2

' Creates the data field column automatically.

sheet.CreateAutoGenratedColumns()

sheet.DataSource = ps

sheet.DataBind()

For reference, please check the source code of data binding demos in our feature demos:

http://www.aspose.com/demos/aspose.grid/description/databind/databind2.htm

http://www.aspose.com/demos/aspose.grid/description/databind/databind1.htm

Also, please check the technical articles in the documentation: http://www.aspose.com/documentation/visual-components/aspose.grid-for-.net/data-binding.html

2). I don't find the sizing problem with GridWeb, I tried your code (also tested other units e.g.., pixel, point etc.) and it works fine:

GridWeb1.Height = New Unit(60, UnitType.Percentage)

GridWeb1.Width = New Unit(75, UnitType.Percentage)

By the way where do you place this code? I mean which event / object / control you are using to write the code above. I places it in the Page_Load event for your info.

Thank you.

The Dataset has data in it. I ran in in SQL Enterprise Manager and checked the row count on the dataset in my code.???

The databind and the sizing code are in the Page_Load event.

Thanks.

Ivan

Hi,

We appreciate if you could create a sample test web project with all the source files (for backend, you may also use some dummy table in MS Access Northwind database), zip it and post it here to reproduce both the issues you have mentioned. We will check it soon.

Also, kindly mention your env. OS, .NET framework version, IIS settings, Browser Type etc.

Thank you.

Attached is a zip of the project. Included is an Access database I used with the same problem I experienced with SQL Server.

OS is XP Professional. IE Verv 6, .Net Framework v2.0.50727

Please advise.

Thank you.

Ivan

Hi,

Thanks for providing us the template project.

Please change your code to:

'Dim db As DemoDatabase = New DemoDatabase()
Dim path As String = Page.MapPath(".")
path = path.Substring(0, path.LastIndexOf("\"))
path = path.Substring(0, path.LastIndexOf("\"))
Dim oledbconnection1 As OleDb.OleDbConnection
Dim oledbcommand1 As OleDb.OleDbCommand
oledbconnection1 = New OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\inetpub\wwwroot\gridtest\wms.mdb;User Id=admin;Password=;")
oledbcommand1 = New OleDb.OleDbCommand
oledbcommand1.Connection = oledbconnection1
oledbcommand1.CommandTimeout = 600

Dim ssql = "Select ItemNo,Description from tItemNo order by ItemNo "
oledbcommand1.CommandText = ssql
oledbcommand1.CommandType = System.Data.CommandType.Text
oledbconnection1.Open()
Dim ps = New DataSet
Dim madaptor = New OleDb.OleDbDataAdapter(oledbcommand1)
madaptor.Fill(ps)
oledbconnection1.Close()

Dim sheet As WebWorksheet = GridWeb1.WebWorksheets(0)

' Clears the sheet.
sheet.Cells.Clear()

sheet.DataSource = ps

' Enables creating in-sheet headers.
sheet.EnableCreateBindColumnHeader = True

' Data cells begin from row 2.
sheet.BindStartRow = 2

sheet.CreateAutoGenratedColumns()

sheet.DataBind()

GridWeb1.Height = New Unit(60, UnitType.Percentage)
GridWeb1.Width = New Unit(75, UnitType.Percentage)

Thank you.

Perfect...that worked.
Thanks for your help.

Ivan