Hi,
I'm having a problem binding a DataTable to a WebGrid. This is the setup:
There's a button on the page that causes a postback. And during the postback in the event method, I dynamically define each UltraWebColumn and then add each column to the WebGrid. Then after each column is defined, I assign the datasource to the DataTable and then execute the WebGrid.DataBind() method to bind.
So, this is the issue. When I click the button for the first time, no data is rendered to the page. But, the WebGrid will render data when the button is clicked a second time and any other time after. But when I clear the webgrid at runtime then click the button to render the grid, no data is rendered again until I click the the button a second time.
Does anyone have an idea why this might be happening? Thanks.
An 'Infragistics Developer Support Engineer' by the name of Vikas has helped me out with this issue. I thought I would post the resolution in case anybody else had came across this issue. Well, it turns out that I was doing everything correctly except for 1 property. Apparently the 'IsBound' property is only required to be set to true when creating custom columns while auto generating columns. I was setting the 'IsBound' property on the 'UltraGridColumn' object to true while setting the 'AutoGenerateColumns' to false.
Thanks Vikas.
Well, the reason I'm adding the columns dynamically is because the result set from the DataTable is being generated at runtime. The application I'm working on allows the user to define a query with their chosen set of columns, then the user would execute that query to return a result set to display. It's very similiar to displaying a report. So, because I would never know what columns the user chooses to view, I have to dynamically create each column to display the grid.
Thanks for your .02 cents. I appreciate the help.
I thought I would add my .02 cents in here just for the fun of it.
Just a couple questions FirstWhy are you adding the columns dynamcally to your ultraWebGrid and then binding the grid to a datasource?
Are you trying to insert and additional Column or all columns in your DatTable?
If you are just trying to reformat the text in your columns of your datatable then insted bind the table as you would normally and allow fo generated columns.
Then inside of the GridReport_InitializeLayout() event you can change your text on the fly depending on the column you are processing.
This is just example code:
for x = 0 to e.Layout.Bands(0).Columns.Count() - 1{ if e.Layout.Bands(0).Columns(0).Header.Key="whatever your column name in the table is" { e.Layout.Bands(0).Columns(iLoopCount).HeaderText = "Some new columns header" }}
I have a better example on my website located here, it uses a Grid View but it also applies to infragistics.
http://www.aboutmeadows.com/articles/making-a-client-customizable-asp.net-gridview.aspx
Let me know if this helps
Thanks
Unfortunately, the problem is beyond what I can diagnose directly. Please submit a support incident to Infragistics Developer Support from this page of our website, and a Developer Support Engineer will assist you further.It would be very helpful if you can provide a sample project that we can run and debug that reproduces the problem. This will ensure that what Developer Support tests is as close to what you're working with as possible.
Thanks for the response Vince. I've tried what you've suggested but the outcome is still the same. I'm doing exactly as you suggested above and still no luck building the grid dynamically. Here's a copy of the code I'm using to build the grid:
protected void OnButtonClicked(object sender, CommandEventArgs e) { BuildWebGrid(); }
protected virtual void BuildWebGrid() { foreach (Field f in FieldList) { UltraGridColumn col = new UltraGridColumn(true); col.BaseColumnName = f.Name; col.IsBound = true col.Header.Caption = f.Name; UltraWebGrid1.Columns.Add(col); } UltraWebGrid1.DataSource = ResultSet; UltraWebGrid1.DataBind();}