I'm creating a nested view, for which I am using a DataSource different from the main grid. This is working perfectly, I have the whole thing wired up and looking good.
However, I need to do some stuff on the server side to change what is displayed in the nested view based on some values in the nested view. Simple stuff like if one value is "NO" then don't show a label. I'm able to detect and manipulate the controls in the nested view so far but I am stuck as to how to get the values from the datasource of the nested view.
I also don't know when to do the hiding/showing of the items. Do I do it OnItemCreated? OnItemCommand? OnNeedDataSource? Right now I am doing it OnItemCreated but I have no idea if that is the right way.
Here's my datasource, the Nested View settings, and my ItemCreated. Line 13 in the C# is what I know is wrong.
<asp:ObjectDataSource ID="dsViewCredit" runat="server" SelectMethod="GetSingleCredit" TypeName="ASIGlobalWebSitePublic.AdminPortal.components.AdminCredit"> <SelectParameters> <asp:Parameter Name="ID" Type="Int32" /> </SelectParameters> </asp:ObjectDataSource>
<NestedViewSettings DataSourceID="dsViewCredit">
<ParentTableRelation>
<telerik:GridRelationFields DetailKeyField="ID" MasterKeyField="ID" />
</ParentTableRelation>
</NestedViewSettings>
01.protected void Grid_ItemCreated(object source, GridItemEventArgs e)
02. {
03. if (e.Item is GridNestedViewItem)
04. {
05.
06. GridNestedViewItem gridNestedViewItemObj = e.Item as GridNestedViewItem;
07. GridDataItem parentItemObj = (e.Item as GridNestedViewItem).ParentItem;
08. if (gridNestedViewItemObj == null || parentItemObj == null)
09. return;
10.
11. if (gridNestedViewItemObj.OwnerTableView.DataKeyValues != null)
12. {
13. string BillingName = gridNestedViewItemObj.OwnerTableView.DataKeyValues[parentItemObj.ItemIndex]["BillingName"].ToString();
14.
15.
16. Panel BillingInfo = (Panel)((GridDataItem)e.Item).ChildItem.FindControl("pnlBillingInfo");
17. Label BillingSame = (Label)((GridDataItem)e.Item).ChildItem.FindControl("lblBillingSame");
18.
19.
20. if (!String.IsNullOrEmpty(BillingName))
21. {
22. BillingInfo.Visible = true;
23. BillingSame.Visible = false;
24. }
25. else
26. {
27. BillingInfo.Visible = false;
28. BillingSame.Visible = true;
29. }
30.}
31.}
32.}
