3 Answers, 1 is accepted
0
Princy
Top achievements
Rank 2
answered on 22 Oct 2013, 04:29 AM
Hi Carlos,
Please try the sample code snippet to access a radgrid inside NestedViewTemplate.
ASPX:
C#:
Thanks,
Princy
Please try the sample code snippet to access a radgrid inside NestedViewTemplate.
ASPX:
<
telerik:RadGrid
ID
=
"RadGrid1"
runat
=
"server"
OnNeedDataSource
=
"RadGrid1_NeedDataSource"
AllowPaging
=
"true"
OnItemCommand
=
"RadGrid1_ItemCommand"
>
<
MasterTableView
DataKeyNames
=
"CustomerID"
>
<
NestedViewTemplate
>
<
telerik:RadGrid
ID
=
"RadGrid2"
runat
=
"server"
OnNeedDataSource
=
"RadGrid2_NeedDataSource"
/>
</
NestedViewTemplate
>
</
MasterTableView
>
</
telerik:RadGrid
>
C#:
protected
void
RadGrid1_NeedDataSource(
object
sender, GridNeedDataSourceEventArgs e)
{
RadGrid1.DataSource = GetDataTable(
"SELECT CustomerID, CompanyName, ContactTitle FROM Customers"
);
}
protected
void
RadGrid2_NeedDataSource(
object
sender, Telerik.Web.UI.GridNeedDataSourceEventArgs e)
{
GridDataItem parentItem = ((sender
as
RadGrid).NamingContainer
as
GridNestedViewItem).ParentItem
as
GridDataItem;
(sender
as
RadGrid).DataSource = GetDataTable(
"SELECT OrderID, EmployeeID, CustomerID FROM Orders where CustomerID='"
+ parentItem.GetDataKeyValue(
"CustomerID"
).ToString() +
"'"
);
}
protected
void
RadGrid1_ItemCommand(
object
sender, GridCommandEventArgs e)
{
if
(e.CommandName == RadGrid.ExpandCollapseCommandName && !e.Item.Expanded)
{
GridDataItem parentItem = e.Item
as
GridDataItem;
RadGrid grid = parentItem.ChildItem.FindControl(
"RadGrid2"
)
as
RadGrid;
grid.Rebind();
}
}
public
DataTable GetDataTable(
string
query)
{
String ConnString = ConfigurationManager.ConnectionStrings[
"Northwind_newConnectionString3"
].ConnectionString;
SqlConnection conn =
new
SqlConnection(ConnString);
SqlDataAdapter adapter =
new
SqlDataAdapter();
adapter.SelectCommand =
new
SqlCommand(query, conn);
DataTable myDataTable =
new
DataTable();
conn.Open();
try
{
adapter.Fill(myDataTable);
}
finally
{
conn.Close();
}
return
myDataTable;
}
Thanks,
Princy
0
Carlos
Top achievements
Rank 1
answered on 22 Oct 2013, 02:47 PM
that resolved thanks, i was putting in itemcreated not itemcommand.
But i have another problem, i tried many way hide on columns in the table and im not getting nothing even if i try to count the columns it gieves 0, how can i hide a column in the parent and child grid.
Best Regards
But i have another problem, i tried many way hide on columns in the table and im not getting nothing even if i try to count the columns it gieves 0, how can i hide a column in the parent and child grid.
Best Regards
0
Princy
Top achievements
Rank 2
answered on 23 Oct 2013, 04:32 AM
Hi Carlos,
In order to hide a column in the Parent grid you can try the following code snippet:
C#:
In order to hide a column in the nested view grid,please try the following:
C#:
Thanks,
Princy
In order to hide a column in the Parent grid you can try the following code snippet:
C#:
protected
void
RadGrid1_PreRender(
object
sender, EventArgs e)
{
RadGrid1.MasterTableView.GetColumnSafe(
"CustomerID"
).Visible =
false
;
}
In order to hide a column in the nested view grid,please try the following:
C#:
protected
void
RadGrid1_ItemCommand(
object
sender, GridCommandEventArgs e)
{
if
(e.CommandName == RadGrid.ExpandCollapseCommandName && !e.Item.Expanded)
{
GridDataItem parentItem = e.Item
as
GridDataItem;
RadGrid grid = parentItem.ChildItem.FindControl(
"RadGrid2"
)
as
RadGrid;
grid.Rebind();
grid.MasterTableView.GetColumnSafe(
"OrderID"
).Visible =
false
;
}
}
Thanks,
Princy