Using server templates for component art grid

This post has 6 replies

Not Ranked
Posts: 11
pembrooke Posted: Mon Apr 27, 2009 @ 9:09 AM
I'm attempting to create a component art grid using a server side template that uses a asp.net dropdown control. I see examples of using a component art combo box control in the server template, but unfortunely, I'm using component art 2006. Do you have any examples creating a asp.net dropdown list in a server template in vb.net 1.1 framework? Here's my code, but I'm having issues loading the drop down on the insert command: Edit Delete Update Cancel Insert | Cancel
Top 10 Contributor
Posts: 6,149
stephen Posted: Mon Apr 27, 2009 @ 10:39 AM
What's the issue you're having- is the data not loading into the dropdown at all? You've obviously seen the way we do it with the combobox- the code would be very similar (the data is set and bound on the server).
Stephen Hatcher, Developer Support Manager
Not Ranked
Posts: 11
pembrooke Posted: Mon Apr 27, 2009 @ 10:51 AM
The data is loading in the dropdown but when the client insert fires, it shows the dropdown index value as 'undefined' in the javascript:

function insertRow(grid,rowId)
{
grid.EditComplete();
if (typeof(grid.Data[rowId]) != 'undefined')
{
if (grid.Data[rowId][1][0] == '')
{
alert('You cannot insert a row without selecting a test.');
grid.Delete(grid.GetRowFromClientId(rowId));
}
else if (grid.Data[rowId][2][0] == '')
{
alert('You cannot insert a row without selecting a test result.');
grid.Delete(grid.GetRowFromClientId(rowId));
}
}
}

The when I attempt to edit with the edit command, the dropdown will not appear.

Are there any examples out there with a dropdown used in a server template?
Top 10 Contributor
Posts: 6,149
stephen Posted: Mon Apr 27, 2009 @ 11:24 AM
My guess is that you haven't defined the customedit get and set expressions (if you look at the demo again, you'll see that these are used with the combobox). These are required to get and set the values on the custom edit control. I made a very quick example by changing the combobox in the demo to a standard framework dropdownlist. You've already seen the server code, so here's the modified client code. First, the column and template:

<ComponentArt:GridColumn DataField="CategoryId" HeadingText="Category" ForeignTable="Categories" ForeignDataKeyField="CategoryID" ForeignDisplayField="CategoryName" EditControlType="Custom" EditCellServerTemplateId="StandardTemplate" CustomEditSetExpression="setStandardCategory(DataItem)" CustomEditGetExpression="getStandardCategory()" Width="140" />

 <ComponentArt:GridServerTemplate ID="StandardTemplate">
                <Template>
                    <asp:DropDownList runat="server" ID="ddl"></asp:DropDownList>
                </Template>
            </ComponentArt:GridServerTemplate>


Note the name of the dom object: this may be different in your case. The name is generated, and takes the form of GridID_GridLevel_GridColumn_OriginalName.

I hope this helps.
Stephen Hatcher, Developer Support Manager
software.aerworldwide Posted: Wed Feb 10, 2010 @ 10:34 AM

Does you JS library support get and set edit expressions for drop downlist? or only for combo box?

Top 10 Contributor
Posts: 6,149
stephen Posted: Thu Feb 11, 2010 @ 9:58 AM

There's no inherent combobox support in the get/ set expressions: you just supply the name of the js functions you want to fire when the edit expressions are needed.  For a drop down list you'll need to find the dom element using it's modifed client id, which you don't have to do with a combobox, as you'll use it's client side object model instead.

Stephen Hatcher, Developer Support Manager
Not Ranked
Posts: 8
canary Posted: Tue Apr 12, 2011 @ 10:05 PM
This will help anyone using Component ART 2006.1.1283.2 JQuery and an ASP Dropdown list (We don't have the combo box in our version of the componentart set (old))

  function getBrand()
  {
    var ddl = $("[id$='_ComboBox1']").first();
    var ddl_id = ddl.attr("id");
    return [$("#" + ddl_id).val(), $("#" + ddl_id).text()];
  }
  var item;
  function setBrand(DataItem)
  {
  var ddl = $("[id$='_ComboBox1']").first();
  var ddl_id = ddl.attr("id");
  item=DataItem;

    if (DataItem.GetMember('BrandID').Value != ''){
        $("#" + ddl_id).val(DataItem.GetMember('BrandID').Value);
    }
  } 


<ServerTemplates>
            <ComponentArt:GridServerTemplate ID="ComboBoxTemplate">
                <Template>
       
                    <asp:DropDownList ID="ComboBox1" runat="server"  Width="120" />
                </Template>
            </ComponentArt:GridServerTemplate>
        </ServerTemplates>
Page 1 of 1 (7 items)