Jump to content
Software FX Community

Unbound Mode - How do you add DataFields in code?


John1grid

Recommended Posts

I am a new user.

Reference Unbound Mode

1. How do you add DataFields in code?

Your online help does not show how to do it in code.

http://support.softwarefx.com/SupportDocTree.aspx?Prod=GridFX10&Type=P

Instead it shows how to do it using the Visual Studio Properties Windows (Right now I have an "error creating control" situation so I cannot use the wizard)

I tried:

  GridFX.WebForms.DataField df;

  df = new GridFX.WebForms.DataField(df);

  df.Title = "StartDate";

  Grid1.DataFields.Add(df);

But:

Error 3 Cannot create an instance of the abstract class or interface 'GridFX.WebForms.DataField' 

2. Also, where can we see example solutions using Grid FX? Can we see the code for the online demonstrations of the grid?

I have found very few, incomplete, examples in the online Grid fx programmer's guide.

3. In my first attempt, I tried setting a DataSource having 3 rows of data.  The grid displays and shows 3 blank rows, no column headings.

 Grid1.DataSource = FastFetchMgr.Library.Manager.MgtPickLineManager.GetQtyPickedPerSecondByDateList(SelectedUserid, UserContext.Session.Warehouse_ID, fromDate, toDate);

  Grid1.DataBind();

When I debug I see the right data rows in Grid1.DataSource  (but nothing displayed in the grid)

Grid1.Columns has count=1

Grid1.Items has Count=3

 

 

 

Link to comment
Share on other sites

Hi, thanks for using Grid FX.  We are working to enhance the documentation, and eventually it'll solve most questions.  In the meantime we're happy to help personally. 

Regarding your issues:

1) Design-time "Error creating control."  Does this happen with every grid that you drop into the designer, or just the grid in question? 

2) Cannot create instance of abstract class "DataField".  DataField is an abstract class and has sub classes that are specific to the type of data they represent in the UI.  There are all kinds.  The primitive ones are TextField, BooleanField, DateTimeField, ImageField, and NumberField.  In addition, since you are binding to a data source, you'll want to set a DataPath, so it knows what data column it points to.  If your fields are static, meaning they never change, you are better off creating them in the page markup.  This will avoid any timing issues, which is appears you have.  But to add the fields, you just need to put the code in the page load like so:

protected void Page_Load(object sender, EventArgs e){ if ( !IsPostback ){ TextField newField = new TextField();     newField.DataPath = "first_name";  newField.Title = "First Name";     Grid1.DataFields.Add(newField); }}

But again, I recommend using the markup to declare your fields.  It's much easier.  If you are having problems with the visual designer, you can always switch to markup view.  The markup would be something like:<GridFX:Grid ID="Grid1" runat="server"><DataFields><GridFX:NumberField DataPath="agent_id"></GridFX:NumberField><GridFX:TextField DataPath="first_name"></GridFX:TextField>

3)  Setting data source.  While you can set the DataSource property yourself, that is not the best practice is to set the DataSourceInCode property to true and then handle the DataSourceSelecting event.  This way, the grid can "pull" the data source when necessary, rather than pushing it in the page load, which will result in unnecessary data binding when things happen in the UI.

Your markup would be like:

<GridFX:Grid ID="Grid1" runat="server" DataSourceInCode="True" ondatasourceselecting="Grid1_DataSourceSelecting">

And the event handler would look like:

protected void Grid1_DataSourceSelecting(object sender, GridFX.WebForms.DataSourceSelectingEventArgs e){e.DataSource = mydata;}

That will solve your data binding problems.

 If you do these things, your grid should work fine.  Thanks, and please let me know if this helps and whether the design-time error is just for that grid.

 

Link to comment
Share on other sites

Stephen,

Thank you for your helpful response.  Probably you resolved most issues I reported except I still have a problem.  I get an error when I drag a grid control from the toolbox onto a web user control.

Error in Visual Studio error list:

 Warning 1 D:\wwwroot\FastFetchMgr\FastFetchMgr.WebSite3.5\Controls\WH\GraphControl1.ascx:

ASP.NET runtime error: Could not load file or assembly 'GridFX.WebForms, Version=1.0.2799.23418, Culture=neutral, PublicKeyToken=a1878e2052c08dce' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040) D:\wwwroot\FastFetchMgr\FastFetchMgr.WebSite3.5\Controls\WH\GraphControl1.ascx 1 1 FastFetchMgr.WebSite3.5

Error displayed on control in designer:

Error Creating Control - Grid1

Failed to create designer 'GridFx.WebForms.Grid, GridFx.WebForms.Version 1.0.2986.27353

 Note the version of the dll in my bin folder of the project is:

Version 1.0.2986.27353

but one of the error messages mentions a different version.

 This happened after I 1) Installed latest ChartFX, and 2) Installed latest GridFX.  Formerly I had installed older versions of both.

Link to comment
Share on other sites

 

Stephen,

I added the following to web config after <appSettings> section:

 <runtime>

  <dependentAssembly>

<assemblyIdentity name="GridFx.WebForms.Grid" publicKeyToken="a1878e2052c08dce" culture=""/>

<bindingRedirect oldVersion="1.0.2799.23418" newVersion="1.0.2986.27353"/>

  </dependentAssembly>

 </runtime>

I still see the error in the designer for the grid control but the version mentioned in the error message is the new version.

And the grid now has the new features such as the OnDataSourceSelecting event.

In the design view the "error creating control" message is long and I don't know how to copy it. Part of it is:

Could not load file or assembly GridFX.Designer.dll ....

Could not load GridFX.Designer, Version 1.0.2986.27353

Most new code executes but upon the Grid1.databind I get error:

"Type must be one of the .NET numeric types" 

I will investigate the field definitions and the data.

Link to comment
Share on other sites

Reference the error:

"Type must be one of the .NET numeric types" 

Stephen,

I did not find any documentation about the DataField types. For example searching for "NumberField" found nothing.  But I found the problem is I defined a field:

GridFX:NumberField

that apparently works only for integers.

But the data vaules are real numbers not integers.  So I need a field type that can handle real values.  What is it?

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...