I'm using aspose.cells.gridweb version 2.7.18.2001
asp:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="dynamicAsposeGridWeb.WebForm1" %>
<%@ Register Assembly="Aspose.Cells.GridWeb" Namespace="Aspose.Cells.GridWeb" TagPrefix="acw" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<acw:gridweb ID="gridWeb1" runat="server"></acw:gridweb>
</div>
</form>
</body>
</html>
code behind:
using System;
using System.Data;
using System.Data.OleDb;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Aspose.Cells.GridWeb;
using Aspose.Cells.GridWeb.Data;
using System.Drawing;
namespace dynamicAsposeGridWeb
{
public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack == true)
{
License license = new License();
license.SetLicense("Aspose.Cells.lic");
String connString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\\Program Files\\Aspose\\Aspose.Cells for .NET\\Demos\\Common\\Database\\demos.mdb";
OleDbConnection conn = new OleDbConnection(connString);
OleDbCommand cmd = new OleDbCommand("SELECT *, -1 FROM PRODUCTS", conn); //<-- neg value was crashing
OleDbDataAdapter da = new OleDbDataAdapter(cmd);
DataSet ds = new DataSet();
conn.Open();
da.Fill(ds, "PRODUCTS");
conn.Close();
WebWorksheet ws = gridWeb1.WebWorksheets[0];
ws.Cells.Clear();
ws.EnableCreateBindColumnHeader = true;
ws.DataSource = ds.Tables[0];
ws.CreateAutoGenratedColumns();
// turn sort off
for (int i = 0; i < ws.BindColumns.Count; i++)
{
ws.BindColumns[i].EnableSort = false;
}
ws.DataBind();
Aspose.Cells.GridWeb.TableItemStyle style;
for (int i = 0; i < ws.Cells.Count; i++)
{
WebCell cell = ws.Cells[i];
style = cell.GetStyle();
if (cell.Row == 0)
{
style.ForeColor = Color.Red;
style.VerticalAlign = VerticalAlign.Middle;
}
ws.Cells.SetStyle(cell.Row, cell.Column, 1, 1, style);
}
ws.Cells.SetRowHeight(0, Unit.Point(48));
}
}
}
}