We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Using BindColumn- Column headers end up in row 1 of worksheet

Using CreateAutoGenratedColumns, column headers are rendered in the column headers of the grid, as expected.

Me.gridTest.WebWorksheets(0).DataSource = dsProgInfo
Me.gridTest.WebWorksheets(0).CreateAutoGenratedColumns()
Me.gridTest.WebWorksheets(0).DataBind()

However, when creating the BindColumns manually, the caption is ending up in the first row of the datasheet (and in the header, it just shows the excel style headers, ie: A B C D E F)

Dim gridColumn As New Aspose.Grid.Web.BindColumn
gridColumn.Caption = "xxxCOLUMN NAMExxx"
worksheet.BindColumns.Add(gridColumn)

Is there a way to do this?

ok, this works:

worksheet.Cells.SetColumnCaption(iColumn, meta.DisplayName)

But, now row(0) is blank, and column sorting no longer works.

Hi,

Please use the following line for your need:

worksheet.EnableCreateBindColumnHeader = False

For further reference, please check the data-binding demos of Aspose.Grid.Web.

Thank you.

I tried that, and now the column headers are blank.

I have looked at all of the demos, you don't seem to have an example where you are:

1) Manually binding columns
2) The column headers are in the worksheet header, not the first row
3) You are not using .CreateAutoGenratedColumns
4) The columns are sortable

I have spent 2 hours on this and still cannot get it to work. Can you post the code that is in your CreateAutoGenratedColumns function as it seems to be able to accomplish this.

Hi,

Well, you do need to utilize Worksheet.CreateAutoGeneratedColumns() method. I utilize the Data Binding at runtime demo: http://www.aspose.com/demos/visual-components/aspose.grid/csharp/demos/data-bind/databind2.aspx but change its code a bit to make it more simple. Moreover, by default BindColumn.EnableSort is set to true.

e.g..,

protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
this.dataSet11 = new Aspose.Grid.Web.DemosCS.DataBind.DataSet1();

WebWorksheet sheet = GridWeb1.WebWorksheets[0];
// Specifies the datasource for the sheet.
sheet.DataSource = dataSet11;
sheet.DataMember = "Products";

sheet.EnableCreateBindColumnHeader = false;

// Data cells begin at row 1;
sheet.BindStartRow = 1;

// Creates the data field column automatically.
sheet.CreateAutoGenratedColumns();


// Modifies a column's number type.
sheet.BindColumns["UnitPrice"].NumberType = NumberType.Currency3;

// Modifies column headers' background color.
for (int i = 0; i < sheet.BindColumns.Count; i++)
{
sheet.BindColumns[i].ColumnHeaderStyle.BackColor = Color.SkyBlue;
}


DemoDatabase db = new DemoDatabase();
string path = Server.MapPath("~");
path = path.Substring(0, path.LastIndexOf("\\"));
db.oleDbConnection1.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + path + "\\Database\\demos.mdb";
try
{
// Loads data from database.
db.oleDbDataAdapter1.Fill(dataSet11);
}
finally
{
db.oleDbConnection1.Close();
}

// Binding.
sheet.DataBind();

}
}
Thank you.

I don't think I can use CreateAutoGeneratedColumns because I need custom captions, and I am not displaying all of the columns in the underlying dataset.

Is it possible to remove some of the bound columns that are automatically created by CreateAutGeneratedColumns, and update the ColumnCaption on the others after they have been automatically created?

I looked at the code in CreateAutoGenratedColumns() and couldn't find anything special that it is doing.

CreateCaptions() seems to be where a sort columns is set:
If column.EnableSort Then
Dim hyperlink As Hyperlink = Me._hyperlinks.AddHyperlink(cell)

hyperlink.ActionType = HyperlinkActionType.CellCommand
hyperlink.CellCommand = ("_BCSORT#" & i)
hyperlink.Text = column.Caption
End If

But I couldn't find anything that calls that, is that function even used? Are you one of the developers that works on the webgrid product? It would be a lot easier if you could quickly ask them rather than me disassembling your code to see what is going wrong.

Hi,

I don't think I can use CreateAutoGeneratedColumns because I need custom captions, and I am not displaying all of the columns in the underlying dataset.

Is it possible to remove some of the bound columns that are automatically created by CreateAutGeneratedColumns, and update the ColumnCaption on the others after they have been automatically created?

Well, you may try to use BindColumn.Width attribute to set it to 0 to hide a bound column. Moreover, if you want to change the caption of a bound column, you may use BindColumn.Caption property for your need. Following is a part of code in VB.

e.g..,

' Creates in-sheet column headers.
sheet.EnableCreateBindColumnHeader = False

'
Data cells begin at row 1;
sheet.BindStartRow = 1

' Creates the data field column automatically.
sheet.CreateAutoGenratedColumns()

'
Hide the first bound column
sheet.BindColumns(0).Width = 0

' Change the caption of of a bound column
sheet.BindColumns("ProductName").Caption = "MyProducts"

If you still have some queries, feel free to ask Henry (Lead developer of Aspose.Grid.Web) here, so he can help you soon.

Thank you.