Jump to content
Software FX Community

Add Grid Row Programmatically


pbursch
 Share

Recommended Posts

If the grid is bound to data, you cannot add items as the grid will automatically clear them when binding.  Adding items manually only makes sense for unbound grids. Do you need to work with an unbound Grid? If that is the case, first you need to create grid fields and then populates them programmatically.

The easiest way to accomplish this:

1. Drop an empty Grid FX object from the toolbar into your web page.

2. Select the Grid FX object.

3. If the Properties Window is not displayed, go to View menu and select it or press F4 .

4. In the properties window, expand the Fields category.

5. Click on the More button and the GridField Collection Editor appears

6. Select the field type and Add as many fields as you need. In this example we added two TextFields: FirstName, LastName and one NumberField: Salary

7. Once the grid shows a column for every field added, you just need to add some code to populate the grid:

protected void Page_Load(object sender, EventArgs e)

  {

  if (!IsPostBack)

  {

  if (Grid1.Items.Count == 0)

  {

  GridItem item = new GridItem();

  item.DataValues.Add(Grid1.Fields["Firstname"],"Michael");

  item.DataValues.Add(Grid1.Fields["Lastname"], "Jordan");

  item.DataValues.Add(Grid1.Fields["Salary"], 1000);

  Grid1.Items.Add(item);

  item = new GridItem();

  item.DataValues.Add(Grid1.Fields["Firstname"], "Tiger");

  item.DataValues.Add(Grid1.Fields["Lastname"], "Woods");

  item.DataValues.Add(Grid1.Fields["Salary"], 2000);

  Grid1.Items.Add(item);

  }

  }

  }

6y6yyyy.txt

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.

 Share

×
×
  • Create New...