Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
1360
Programmatically Create Bound WebGrid?
posted

The current examples of creating WebGrids all use "mickey-mouse"scenarios with adding columns and rows manually - hardly realistic. Does anybody have experience of populating a databound grid programmatically? I am doing this to try and curcumvent some issues that I am experiencing with WebGrid.

To start with, I have a Webgrid on a web page thst is minimalist:

        <igtbl:UltraWebGrid ID="ProjectAssetList" runat="server"></igtbl:UltraWebGrid>

On the page load event I do the following to the Grid:

  • Clear the Columns
  • Clear the Bands
  • Set the grid width (in pixels)
  • Set the Visibility True
  • Assign the DataSourceID to the name of a valid DataSource on the web page
  • Set the DataKeyField
  • DataMember = "DefaultView"
  • Set AutoGenerateColumns = False;
  • Assign properties to the foreground and background colours, font styles and border properties for:
  1. FrameStyle
  2. EditCellStyle
  3. RowStyleDefault
  4. RowAlternateStyleDefault
  5. HeaderStyleDefault
  6. FooterStyleDefault
  • Set RowHeightDefault = 17px
  • Set TableLayout = Fixed

To mimic the declarative structure (where Columns are always declared within bands) I create an UltraGridBand object and assign its properties:

  • Set AlternateRowStyling = Yes
  • RowSelectors = Yes
  • SelectTypeRow = Single
  • AllowUpdates = Yes
  • ClickCellAction = Edit

Then I add Columns to the Band object. For each UltraGridColumn I set the following:

  • Column Heading
  • AllowUpdate = Yes/No according to those columns that are editable
  • Column Width
  • Hidden = True/False depending on visibility
  • Key = Database Field Name
  • BaseColumnName = Database Field Name
  • IsBound = true
  • Where numeric, I set the Format property
  • Append the UltraGridColumn to the Band

Finally, I append the Band to the grid and perform a Databind.

I get a "No Data To Display" message.

Any ideas as to what I am missing? 

I could supply the source code for this but it is picking-up data from database tables so I thought the explanation above would be clearer.

VS 2008 Pro, IG 2008v1, C#.

Kind regards

Paul

 

 

 

  • 8680
    posted

    PaulShearing said:
    Does anybody have experience of populating a databound grid programmatically? I am doing this to try and curcumvent some issues that I am experiencing with WebGrid.

    Sounds like doing it the hard way to me. What "issues"?

    PaulShearing said:
    I could supply the source code for this but it is picking-up data from database tables so I thought the explanation above would be clearer.

    The code might help us spot the problem.  (I've never attempted what you're doing, so I've got my doubts, but I'll be happy to try.)

  • 1763
    posted

    DataBinding works when you set the Grid.DataSource [http://help.infragistics.com/Help/NetAdvantage/NET/2007.2/CLR2.0/html/Infragistics2.WebUI.UltraWebGrid.v7.2~Infragistics.WebUI.UltraWebGrid.UltraWebGrid~DataBind.html]

    So if you're adding bands, columns and rows manually, you shouldn't perform any databinding since the grid will try to load data from the assigned datasource, in this case none. I guess that's why you get the 'No data to display' alert.