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
265
Accessing a control in templated column client side?
posted

Hello,

For some reason I am having trouble with this:  how do I access a control in a templated column through client script?  I can reference the row and the cell that I need, but I can’t set the value of the control (asp:dropdownlist) in the cell.  This is being done from the onclick event of a control outside the grid.

What is the syntax for accessing a control in the cell template? 

The function looks like this so far: 

function FieldSvcClick(source) {

  var item = source.value; //the value of the selected item

  var grid = igtbl_getGridById(GridID);

  if (item == "NotFieldServices") {

       for (i = 0; i < grid.Rows.length; i++) {  //loop through the rows to find the right one

            var row1 = grid.Rows.getRow(i);

            var name = row1.getCell(1).getElement().children[0].innerText; //get the name value in column(1)

            if (name == "Field Services") {

                   row1.getCellFromKey("Required").setValue(1); //this works but is not what I want to do

                   //set the value of the dropdown here

                   return;

}}}}

The templated column looks like this:

<igtbl:TemplatedColumn AllowUpdate="Yes" BaseColumnName="Required" Key="Required" Width="75px">

<CellTemplate>

<asp:DropDownList ID="ddlRequired" runat="server">

<asp:ListItem Value="1">Yes</asp:ListItem>

<asp:ListItem Value="0">No</asp:ListItem>

</asp:DropDownList>

<asp:Label ID="lblRequired" runat="server"></asp:Label>

</CellTemplate>

</igtbl:TemplatedColumn>

  • 12679
    posted

    Hello,

    One way would be once you get a cell reference just return the  DOM Html element and then try to access the children of this DOM element there should be the dropdownlist. You could access the Cell DOM element with the following function: 

    getElement();  

    http://help.infragistics.com/NetAdvantage/ASPNET/2010.2?page=WebGrid_cell_Object_CSOM.html 

    Hope this helps. 

     

     

    • 265
      Suggested Answer
      posted in reply to [Infragistics] Radoslav Minchev

      Thanks for the reply.  I decided to go about this a different way...since the problem was that the IDs for the elements in the templated column are dynamically generated, I am changing the IDs in the grid InitializeRow event using the datakey for the row.  This way I will know the exact ID of the drop down for the specific row I need.

       

       

       

      TemplatedColumn

       

       

      col = (TemplatedColumn)e.Row.Cells.FromKey("Required").Column;

       

       

       

      CellItem ci = (CellItem) col.CellItems[e.Row.Index];

       

       

       

      DropDownList ddl = (DropDownList) ci.FindControl("ddlRequired");

      ddl.ID =

       

      "ddlRequired" + e.Row.DataKey;

      • 265
        posted in reply to Jennifer

        One more thing to add...I found that my solution above did not work for a user control that we have in a templated column.  I solved this by using a jquery selector to find the child control by class.  The user control has a DIV that I assigned a class "typeAheadDiv".  Then in the function I do this:

         

         

         

         

        var cell = row1.getCellFromKey("AssignedApprover").getElement();

        $(cell).children(

         

        ".typeAheadDiv").css("display", "none");

        Hope this might help someone else.