hi
using the web service binding the child grid on expanding event of the js .when you expand the one row it is working ,if we expand all rows using the js only lost row is showing the data.
i downloaded the one sample from the forums and modified here is the code
<script runat="server">
protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e)
{
if (e.Item is GridHeaderItem)
{
GridHeaderItem hitem = (GridHeaderItem)e.Item;
CheckBox chk = new CheckBox();
chk.Attributes["onclick"] = "javascript: ExpandCollapseAllTables()";
hitem["ExpandColumn"].Controls.Add(chk);
}
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Two level hierarchy</title>
<telerik:RadCodeBlock ID="RadCodeBlock1" runat="server">
<script type="text/javascript" src="Script1.js"></script>
<script type="text/javascript">
function pageLoad(sender, args) {
tableView = $find("<%= RadGrid1.ClientID %>").get_masterTableView();
commandName = "Load"
WebService.GetCustomers(0, tableView.get_pageSize(),
tableView.get_sortExpressions().toString(), tableView.get_filterExpressions().toDynamicLinq(),
updateGrid);
}
function ExpandCollapseAllTables() {
for (masterIndex = 0; masterIndex < 2; masterIndex++) {
var firstMasterTableViewRow = $find("<%= RadGrid1.MasterTableView.ClientID %>").get_dataItems()[masterIndex];
if (firstMasterTableViewRow.get_expanded()) {
firstMasterTableViewRow.set_expanded(false);
}
else {
firstMasterTableViewRow.set_expanded(true);
}
}
}
</script>
</telerik:RadCodeBlock>
</head>
<body>
<form id="form1" runat="server">
<div>
<telerik:RadScriptManager ID="RadScriptManager1" runat="server">
<Services>
<asp:ServiceReference Path="~/WebService.asmx" />
</Services>
</telerik:RadScriptManager>
<telerik:RadStyleSheetManager ID="RadStyleSheetManager1" runat="server" />
<telerik:RadGrid ID="RadGrid1" AllowFilteringByColumn="true" Skin="Telerik" runat="server"
GridLines="None" AllowPaging="true" AllowSorting="true"
onitemcreated="RadGrid1_ItemCreated">
<ClientSettings>
<ClientEvents OnCommand="RadGrid1_Command" OnHierarchyExpanding="RadGrid1_HierarchyExpanding" />
</ClientSettings>
<MasterTableView HierarchyLoadMode="Client" ClientDataKeyNames="CustomerID">
<Columns>
<telerik:GridBoundColumn SortExpression="CustomerID" DataField="CustomerID" HeaderText="CustomerID" />
<telerik:GridBoundColumn SortExpression="CompanyName" DataField="CompanyName" HeaderText="CompanyName" />
<telerik:GridBoundColumn SortExpression="ContactName" DataField="ContactName" HeaderText="ContactName" />
<telerik:GridBoundColumn SortExpression="ContactTitle" DataField="ContactTitle" HeaderText="ContactTitle" />
<telerik:GridBoundColumn SortExpression="Country" DataField="Country" HeaderText="Country" />
<telerik:GridBoundColumn SortExpression="City" DataField="City" HeaderText="City" />
</Columns>
<NestedViewTemplate>
</NestedViewTemplate>
</MasterTableView>
<PagerStyle AlwaysVisible="true" />
</telerik:RadGrid>
<asp:Panel ID="Panel1" style="display:none;" runat="server">
<telerik:RadGrid ID="RadGrid2" AllowFilteringByColumn="true" Skin="Telerik" runat="server"
GridLines="None" AllowPaging="true" AllowSorting="true">
<ClientSettings>
<ClientEvents OnCommand="RadGrid2_Command" />
</ClientSettings>
<MasterTableView ClientDataKeyNames="OrderID">
<Columns>
<telerik:GridBoundColumn SortExpression="OrderID" DataField="OrderID" HeaderText="OrderID"
DataType="System.Int32" />
<telerik:GridBoundColumn SortExpression="OrderDate" DataField="OrderDate" HeaderText="OrderDate"
DataType="System.DateTime" DataFormatString="{0:MM/dd/yyyy}" />
<telerik:GridBoundColumn SortExpression="ShipName" DataField="ShipName" HeaderText="ShipName" />
<telerik:GridBoundColumn SortExpression="ShipCity" DataField="ShipCity" HeaderText="ShipdgdfgdCity" />
<telerik:GridBoundColumn SortExpression="ShipCountry" DataField="ShipCountry" HeaderText="ShipCountry" />
</Columns>
</MasterTableView>
<PagerStyle AlwaysVisible="true" />
</telerik:RadGrid>
</asp:Panel>
</div>
</form>
</body>
</html>
script1.js
var commandName = "";
var tableView = null;
var ordersView = null;
var ordersCommandName = "";
function RadGrid1_Command(sender, args) {
args.set_cancel(true);
collapseItems(sender);
commandName = args.get_commandName();
WebService.GetCustomers(tableView.get_currentPageIndex() * tableView.get_pageSize(), tableView.get_pageSize(),
tableView.get_sortExpressions().toString(), tableView.get_filterExpressions().toDynamicLinq(),
updateGrid);
}
function updateGrid(result) {
tableView.set_dataSource(result);
tableView.dataBind();
var dataItems = tableView.get_dataItems();
if (commandName == "Filter" || commandName == "Load") {
WebService.GetCustomersCount(updateVirtualItemCount);
}
}
function updateVirtualItemCount(result) {
tableView.set_virtualItemCount(result);
}
function collapseItems(sender) {
var dataItems = sender.get_masterTableView().get_dataItems();
for (var i = 0, length = dataItems.length; i < length; i++) {
var input = dataItems[i].get_element().cells[0].getElementsByTagName("input")[0];
if (input.className == "rgCollapse") {
input.click();
}
}
}
function RadGrid1_HierarchyExpanding(sender, args) {
collapseItems(sender);
var customerID = args.getDataKeyValue("CustomerID");
var nestedViewItem = args.get_nestedViewItem();
nestedViewItem.cells[1].appendChild($get("RadGrid2"));
ordersView = $find("RadGrid2").get_masterTableView();
ordersCommandName = "Load";
WebService.GetOrdersByCustomerID(customerID, ordersView.get_currentPageIndex() * ordersView.get_pageSize(), ordersView.get_pageSize(),
ordersView.get_sortExpressions().toString(), ordersView.get_filterExpressions().toDynamicLinq(),
updateOrdersGrid);
}
function updateOrdersGrid(result) {
ordersView.set_dataSource(result);
ordersView.dataBind();
if (ordersCommandName == "Filter" || ordersCommandName == "Load") {
WebService.GetOrdersByCustomerIDCount(updateOrdersVirtualItemCount);
}
}
function updateOrdersVirtualItemCount(result) {
ordersView.set_virtualItemCount(result);
}
function RadGrid2_Command(sender, args) {
ordersView = sender.get_masterTableView();
var nestedViewItem = sender.get_element().parentNode.parentNode;
var parentGridDataItem = $find(Telerik.Web.UI.Grid.GetNodePreviousSiblingByTagName(nestedViewItem, "tr").id);
var customerID = parentGridDataItem.getDataKeyValue("CustomerID");
args.set_cancel(true);
ordersCommandName = args.get_commandName();
WebService.GetOrdersByCustomerID(customerID, ordersView.get_currentPageIndex() * ordersView.get_pageSize(), ordersView.get_pageSize(),
ordersView.get_sortExpressions().toString(), ordersView.get_filterExpressions().toDynamicLinq(),
updateOrdersGrid);
}
please help me
downloaded sample file name is 102839_website
thanks and Regards
Srikanth.Narala
| using System; |
| using System.Data; |
| using System.Configuration; |
| using MySql.Data.MySqlClient; |
| using Microsoft.ApplicationBlocks.Data; |
| /// <summary> |
| /// Summary description for CommonDataProvider |
| /// </summary> |
| namespace com.myclass.DAL |
| { |
| public class CommonDataProvider |
| { |
| public static DataTable getDlr() |
| { |
| DataTable ds= null; |
| string str = ConfigurationManager.AppSettings["emgConnectionString"]; |
| MySqlConnection con = new MySqlConnection(str); |
| //MySqlCommand command = con.CreateCommand(); |
| string query = "SELECT * FROM routelog"; |
| //SqlDataAdapter adapter = new SqlDataAdapter(); |
| MySqlDataAdapter myDataAdapter = new MySqlDataAdapter(); |
| myDataAdapter.SelectCommand = new MySqlCommand(query, con); |
| //MySqlDataAdapter myDataAdapter = new MySqlDataAdapter(command); |
| ds= new DataTable(); |
| con.Open(); |
| try |
| { |
| myDataAdapter.Fill(ds); |
| } |
| catch (Exception ex) |
| { |
| WriteLog(DateTime.Now.ToString() + ":" + ex.Message + " " + ex.StackTrace); |
| } |
| finally |
| { |
| con.Close(); |
| } |
| return ds; |
| } |
| public static DataSet GetPageInfo()//(int id) |
| { |
| DataSet ds = null; |
| string str = ConfigurationManager.AppSettings["emgConnectionString"]; |
| string sequel = "SELECT routelog.starttime, status.details AS STATUS, routelog.sourceaddr, routelog.destaddr, messagebody.data AS 'encrpted message' FROM emg.routelog INNER JOIN emg.status ON (routelog.status = status.statusID)INNER JOIN emg.messagebody ON (routelog.msgid = messagebody.id)WHERE (routelog.msgtype =1)"; |
| //if (id > 0) |
| // sequel += " WHERE ID = " + id; |
| //sequel += " ORDER BY PageName"; |
| try |
| { |
| ds = SqlHelper.ExecuteDataset(str, CommandType.Text, sequel); |
| } |
| catch (Exception ex) |
| { |
| WriteLog(DateTime.Now.ToString()+":"+ ex.Message + " " + ex.StackTrace); |
| } |
| return ds; |
| } |
| public static void WriteLog(string msg) |
| { |
| try |
| { |
| //HttpContext context = HttpContext.Current; |
| string path = ConfigurationManager.AppSettings["LogFile"]; |
| //string err = ConfigurationManager.AppSettings["LogFile"]; |
| //Mail.SendMail( |
| //string path = context.Server.MapPath(_path); |
| System.IO.StreamWriter writer = new System.IO.StreamWriter(path, true); |
| writer.WriteLine(msg + " " + DateTime.Now.ToString()); |
| writer.WriteLine(); |
| writer.Close(); |
| } |
| catch { } |
| } |
| } |
| } |
| <asp:ObjectDataSource ID="ObjectDataSource1" runat="server" |
| SelectMethod="getDlr" TypeName="com.cellulant.DAL.CommonDataProvider"> |
| </asp:ObjectDataSource> |
| <asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager> |
| <!-- content start --> |
| <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server"> |
| <AjaxSettings> |
| <telerik:AjaxSetting AjaxControlID="RadGrid1"> |
| <UpdatedControls> |
| <telerik:AjaxUpdatedControl ControlID="RadGrid1" /> |
| </UpdatedControls> |
| </telerik:AjaxSetting> |
| </AjaxSettings> |
| </telerik:RadAjaxManager> |
| <telerik:RadGrid ID="RadGrid1" runat="server" AllowFilteringByColumn="True" |
| AllowPaging="True" AllowSorting="True" |
| GridLines="None" ShowGroupPanel="True" Skin="Sunset" PageSize="50" style="margin-bottom: 117px" |
| Width="900px" AutoGenerateColumns="False" DataSourceID="ObjectDataSource1"> |
| <HeaderContextMenu EnableTheming="True"> |
| <CollapseAnimation Type="OutQuint" Duration="200"></CollapseAnimation> |
| </HeaderContextMenu> |
| <ExportSettings FileName="report" IgnorePaging="True" OpenInNewWindow="True"> |
| <Pdf Creator="cellulant Nigreia Limited" PageHeight="8.5in" PageWidth="11in" /> |
| </ExportSettings> |
| <PagerStyle Mode="NextPrevNumericAndAdvanced" /> |
| <MasterTableView DataSourceID="ObjectDataSource1"> |
| <RowIndicatorColumn> |
| <HeaderStyle Width="20px"></HeaderStyle> |
| </RowIndicatorColumn> |
| <ExpandCollapseColumn> |
| <HeaderStyle Width="20px"></HeaderStyle> |
| </ExpandCollapseColumn> |
| </MasterTableView> |
| <ClientSettings AllowColumnHide="True" AllowDragToGroup="True"> |
| <Selecting AllowRowSelect="True" /> |
| <Scrolling AllowScroll="True" UseStaticHeaders="True" /> |
| </ClientSettings> |
| <FilterMenu EnableTheming="True"> |
| <CollapseAnimation Type="OutQuint" Duration="200"></CollapseAnimation> |
| </FilterMenu> |
| </telerik:RadGrid> |

| <body style="direction: rtl;"> |
| <form id="form1" runat="server"> |
| <div> |
| <asp:ScriptManager ID="ScriptManager1" runat="server" /> |
| <telerik:RadWindowManager ID="RadWindowManager1" runat="server"> |
| <Windows> |
| <telerik:RadWindow ID="rw1" Name="rw1" Behaviors="Close" ShowContentDuringLoad="false" |
| ReloadOnShow="true" VisibleStatusbar="false" BackColor="Gray" Modal="true" runat="server" |
| Height="650" Width="500"> |
| </telerik:RadWindow> |
| </Windows> |
| </telerik:RadWindowManager> |
| <telerik:RadCodeBlock ID="radCodeBlock" runat="server"> |
| <script language="javascript" type="text/javascript"> |
| function OpenRadWindow(url) { |
| var oWnd = window.radopen(null, 'rw1'); |
| oWnd.setUrl(url); |
| return false; |
| } |
| </script> |
| </telerik:RadCodeBlock> |
| <telerik:RadTextBox ID="txt" runat="server"> |
| </telerik:RadTextBox> |
| <asp:Button ID="btnOpen" runat="server" OnClientClick="javascript:return OpenRadWindow('WebForm1.aspx')" |
| Text="pop up 1" /> |
| <asp:Button ID="Button1" runat="server" OnClientClick="javascript:return OpenRadWindow('WebForm2.aspx')" |
| Text="pop up 2 " /> |
| </div> |
| </form> |
| </body> |

I am attempting to retrieve the value of a cell in a RadGrid during the ItemDataBound event. The catch is that I am using an ItemTemplate, which seems to be the root of the problem.
I found http://www.telerik.com/help/aspnet-ajax/grdaccessingcellsandrows.html which states (about half-way down) that “This approach of obtaining cell values works for auto-generated columns and built-in column types except for template columns. For template columns you must find the control in the grid cell and extract its value.”
I agree with that statement (based on my testing), but I cannot find anywhere an example of “finding the control in the grid cell and extracting its value.”
Can someone point me to a relevant example?
My goal is to read the URL for a picture (image source), and set an imagecolumn on the same row to use that image source. This approach works perfectly so long as I do not use an <ItemTemplate></ItemTemplate> block.
Thank you in advance for your help.
Brian Meagher



| <telerik:GridBoundColumn DataField="DateOfBirth" DataType="System.DateTime" |
| Visible = "True" HeaderText="DateOfBirth" SortExpression="DateOfBirth" |
| UniqueName="DateOfBirth" EditFormColumnIndex="1" |
| DataFormatString="{0:dd/MM/yyyy}"> |
| </telerik:GridBoundColumn> |
