问题
I have a javascript, that I need to be run on expand link click
<telerik:RadCodeBlock ID="RadCodeBlock1" runat="server">
<script type="text/javascript">
function RowExpanded(sender, eventArgs) {
alert(123);
}
</script>
</telerik:RadCodeBlock>
I use HierarchyLoadMode="Conditional" for inner grid data load on my aspx page.
<telerik:RadAjaxPanel runat="server">
<telerik:RadGrid ID="rgUsersInSessions" ShowStatusBar="true" OnNeedDataSource="OnNeedDataSourceForGrid" OnDetailTableDataBind="OnDetailTableDateBind" OnItemDataBound="OnAnswerItemBound" runat="server" AutoGenerateColumns="False" PageSize="10"
AllowSorting="True" AllowMultiRowSelection="False" AllowPaging="True" GridLines="None">
<ClientSettings AllowExpandCollapse="True">
<Selecting AllowRowSelect="True"></Selecting>
<ClientEvents OnHierarchyExpanding="RowExpanded" />
</ClientSettings>
<PagerStyle Mode="NumericPages"></PagerStyle>
<MasterTableView EnableHierarchyExpandAll="true" AllowMultiColumnSorting="True" ClientIDMode="Static" HierarchyLoadMode="Conditional">
<DetailTables>
<telerik:GridTableView HierarchyLoadMode="Conditional" EnableHierarchyExpandAll="true" Width="100%" runat="server" ClientIDMode="Static" ShowHeader="False">
<Columns>
<telerik:GridTemplateColumn UniqueName="userQuestion">
<ItemTemplate>
<asp:Label Text='<%# DataBinder.Eval(Container.DataItem, "EventId").ToString() %>'></asp:Label>
</ItemTemplate>
</telerik:GridTemplateColumn>
</Columns>
</telerik:GridTableView>
</DetailTables>
<Columns>
<telerik:GridBoundColumn UniqueName="SessionUserId" Display="False" AllowFiltering="false" DataField="SessionUserId" DataType="System.Int32">
</telerik:GridBoundColumn>
</Columns>
</MasterTableView>
</telerik:RadGrid>
</telerik:RadAjaxPanel>
When I click the expand link at the grid, it expands inner table and load the table date in it, but my javascript function (RowExpanded) wasn't run. On page load I can find the the function on the page, but after clicking the expand link I can't see it anymore.
回答1:
Knowing how some of those features are only available when binding via the client, I'm assuming that method isn't running because you aren't using the JavaScript API. Certain things only work if you are using that API.
You say you can't see the method anymore. Depending on how you are inspecting the page, it could be the tool you are using doing that (I know when working with ajax panels, it changes the viewable response output in tools like Firebug, etc.).
回答2:
Found the problem by myself.
I set ClientIDMode="Static" at
<MasterTableView EnableHierarchyExpandAll="true" AllowMultiColumnSorting="True" ClientIDMode="Static" HierarchyLoadMode="Conditional">
and at
<telerik:GridTableView HierarchyLoadMode="Conditional" EnableHierarchyExpandAll="true" Width="100%" runat="server" ClientIDMode="Static" ShowHeader="False">
But this elements have no setter for ID. It generates onClick javascript where
$find("")
returns null.
来源:https://stackoverflow.com/questions/22405485/telerik-radgrid-with-hierarchy-doesnt-run-client-javascript-on-onhierarchyexpan