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>
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:
Hope this helps.
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;
ddl.ID =
"ddlRequired" + e.Row.DataKey;
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:
$(cell).children(
".typeAheadDiv").css("display", "none");
Hope this might help someone else.