Free Support Forum - aspose.com

Unhandled exception trying to DataBind() a gridWeb with CreateAutoGenratedColumns()

I have a webGrid on as .asp page which I want to populate from a datatable at run time and I want it to automatically generate the column headings.

When it tries to display the page, it throws an unhandled exception. See Stack Trace below.

Also below I have attached a snippet of my .asp code.

If I set the datasource then call .CreateAutoGenratedColumns() then call .DataBind() it throws the error.

If I set the datasource then create a BindColumn and add it to the WebWorksheet, then call .DataBind() it works (but this isn't what I want. I do not know the columns ahead of time, they are whatever is returned to me from my stored procedure call)

Stack Trace:

[ArgumentNullException: Value cannot be null.
Parameter name: input]
   System.Text.RegularExpressions.Regex.Match(String input) +6142595
   System.Text.RegularExpressions.Regex.Match(String input, String pattern, RegexOptions options) +44
   xd217579df7b1e971.x162e606cd2e588ae.xc79ba7b5665427dc(Color& x6c50a99faab7d741) +586
   Aspose.Cells.GridWeb.GridWeb.x6c57becf1c4e05c3() +18398
   Aspose.Cells.GridWeb.GridWeb.OnPreRender(EventArgs e) +773
   System.Web.UI.Control.PreRenderRecursiveInternal() +103
   System.Web.UI.Control.PreRenderRecursiveInternal() +175
   System.Web.UI.Control.PreRenderRecursiveInternal() +175
   System.Web.UI.Control.PreRenderRecursiveInternal() +175
   System.Web.UI.Control.PreRenderRecursiveInternal() +175
   System.Web.UI.Control.PreRenderRecursiveInternal() +175
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2496

ASP

<asp:Panel ID="PanelGridWeb" runat="server">

<acw:GridWeb ID="gwResults" runat="server">

</acw:GridWeb>

</asp:Panel>

<br />

<asp:Panel ID="PanelGridView" runat="server">

<asp:GridView ID="gvResults" runat="server" CssClass="gvResults"

ShowHeaderWhenEmpty="True" onrowdatabound="gvResults_RowDataBound">

<AlternatingRowStyle BackColor="White" Wrap="False" />

<HeaderStyle BackColor="#CCCCCC" />

<RowStyle Wrap="False" />

<SelectedRowStyle BackColor="#CCCCCC" />

</asp:GridView>

</asp:Panel>

<br />

-------------------

Code Behind

WebWorksheet sheet = gwResults.WebWorksheets[0];

sheet.Cells.Clear();

sheet.EnableCreateBindColumnHeader = true;

sheet.BindStartRow = 1;

sheet.DataSource = dt;

// this fails

sheet.CreateAutoGenratedColumns();

//// this works (hard-coded bound columns)

//BindColumn boundCol1 = new BindColumn();

//boundCol1.DataField = "Case ID";

//boundCol1.Caption = "Case ID";

//sheet.BindColumns.Add(boundCol1);

sheet.DataBind();

Hi,


Please see the demos for your reference:
http://www.aspose.com/demos/.net-components/aspose.cells/csharp/grid/data-bind/databind2.aspx

Also refer to the article:
http://www.aspose.com/docs/display/cellsnet/Binding+Worksheet+to+a+DataSet+At+Run+Time+using+GridWeb


Please use our latest version i.e. v2.7.15.2xxx (GridWeb), if you still find the issue, kindly create a sample project (runnable), zip it and post it here to reproduce the issue on our end. Please use MS Access database or hard coded datatable/dataset (that you may create dynamically). Please attach the project here, we will check your issue soon.

Thank you.