Hi All,
I have 2 level grid with MasterTableView and DetailTables. I am using ObjectDataSource to bind data to both of the master and detail tableview. I want to be able to access the rows (or DataItems) in detail table. I have the DetailTableDataBind event defined and which is being firing too. Unfortunately I can not enumerate through the list of Items as I'm getting empty Items list.
Please guide on how can I access the Items in DetatlTable. There is a DataBound event for the DetatlTableView which does nt seem much useful as its event argument is just regular System.EventAgrs. Is there any ItemDataBound event exist for the DetatlTableView ?
Any help on this ?
Thanks
I have 2 level grid with MasterTableView and DetailTables. I am using ObjectDataSource to bind data to both of the master and detail tableview. I want to be able to access the rows (or DataItems) in detail table. I have the DetailTableDataBind event defined and which is being firing too. Unfortunately I can not enumerate through the list of Items as I'm getting empty Items list.
Please guide on how can I access the Items in DetatlTable. There is a DataBound event for the DetatlTableView which does nt seem much useful as its event argument is just regular System.EventAgrs. Is there any ItemDataBound event exist for the DetatlTableView ?
Any help on this ?
Thanks
4 Answers, 1 is accepted
0
Hello Tejas,
For more information how to identify the table to which the current row belongs/is bound you can refer to the help topic linked below:
http://www.telerik.com/help/aspnet-ajax/grid-distinguish-rows-in-hierarchy-on-itemdatabound.html
Regards,
Pavlina
the Telerik team
For more information how to identify the table to which the current row belongs/is bound you can refer to the help topic linked below:
http://www.telerik.com/help/aspnet-ajax/grid-distinguish-rows-in-hierarchy-on-itemdatabound.html
Regards,
Pavlina
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now
0
Tejas
Top achievements
Rank 1
answered on 28 Sep 2011, 05:47 PM
Hi Pavlina,
Thanks for your reply. I have gone through the details but unfortunately, It could not fix my problem.
Code behind:
In the above code, I want to be able to get all the checkboxes placed in GridTemplateColumn and all selecte
Thanks
Thanks for your reply. I have gone through the details but unfortunately, It could not fix my problem.
<
telerik:RadGrid
ID
=
"grdTransOrderDetails"
runat
=
"server"
AutoGenerateColumns
=
"false"
DataSourceID
=
"odsParent"
OnNeedDataSource
=
"grdTransOrderDetails_NeedDataSource"
EnableViewState
=
"true"
OnItemCommand
=
"grdTransOrderDetails_ItemCommand"
PageSize
=
"10"
AllowSorting
=
"false"
AllowMultiRowSelection
=
"False"
OnItemDataBound
=
"grdTransOrderDetails_ItemDataBound"
AllowAutomaticDeletes
=
"false"
AllowAutomaticInserts
=
"false"
AllowAutomaticUpdates
=
"false"
>
<
MasterTableView
DataKeyNames
=
"TranslationOrderDetailID"
HierarchyDefaultExpanded
=
"true"
CommandItemDisplay
=
"None"
>
<
NoRecordsTemplate
>
<
asp:Label
ID
=
"lblNoDetails"
runat
=
"server"
Text
=
"No detail(s) found."
></
asp:Label
>
</
NoRecordsTemplate
>
<
Columns
>
<
telerik:GridEditCommandColumn
UniqueName
=
"EditOrderDetailCmd"
ButtonType
=
"ImageButton"
HeaderText
=
"Edit"
FilterControlAltText
=
"Filter EditCommandColumn"
ItemStyle-HorizontalAlign
=
"Left"
ItemStyle-VerticalAlign
=
"Middle"
>
</
telerik:GridEditCommandColumn
>
<
telerik:GridBoundColumn
FilterControlAltText
=
"SourceLanguageName"
UniqueName
=
"SourceLanguageName"
DataField
=
"LanguageName"
HeaderText
=
"Source Language"
>
</
telerik:GridBoundColumn
>
</
Columns
>
<
DetailTables
>
<
telerik:GridTableView
DataKeyNames
=
"TranslationOrderDetailDocumentID"
Width
=
"100%"
DataSourceID
=
"odsDocument"
PageSize
=
"5"
AllowPaging
=
"true"
runat
=
"server"
Name
=
"Documents"
EnableViewState
=
"true"
AllowAutomaticDeletes
=
"false"
AutoGenerateColumns
=
"false"
AllowAutomaticInserts
=
"false"
AllowAutomaticUpdates
=
"false"
>
<
ParentTableRelation
>
<
telerik:GridRelationFields
DetailKeyField
=
"OrderDetailID"
MasterKeyField
=
"TranslationOrderDetailID"
/>
</
ParentTableRelation
>
<
NoRecordsTemplate
>
<
asp:Label
ID
=
"lblNoDocumentsFound"
runat
=
"server"
Text
=
"No document(s) found."
></
asp:Label
>
</
NoRecordsTemplate
>
<
Columns
>
<
telerik:GridTemplateColumn
HeaderText
=
"Select"
>
<
ItemTemplate
>
<
asp:CheckBox
ID
=
"chkItemSelect"
runat
=
"server"
/>
</
ItemTemplate
>
</
telerik:GridTemplateColumn
>
<
telerik:GridEditCommandColumn
UniqueName
=
"EditCmd"
ButtonType
=
"ImageButton"
HeaderText
=
"Edit"
FilterControlAltText
=
"Filter EditCommandColumn"
ItemStyle-HorizontalAlign
=
"Center"
ItemStyle-VerticalAlign
=
"Middle"
>
</
telerik:GridEditCommandColumn
>
<
telerik:GridButtonColumn
CommandName
=
"Delete"
ButtonType
=
"ImageButton"
Text
=
"Delete"
UniqueName
=
"DeleteCmd"
HeaderText
=
"Delete"
ConfirmText
=
"Are you sure you want to delete ?"
FilterControlAltText
=
"Filter DeleteCommandColumn"
ItemStyle-HorizontalAlign
=
"Center"
ItemStyle-VerticalAlign
=
"Middle"
>
</
telerik:GridButtonColumn
>
<
telerik:GridBoundColumn
FilterControlAltText
=
"DocumentName"
UniqueName
=
"DocumentName"
DataField
=
"DocumentName"
HeaderText
=
"Document Name"
>
</
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
FilterControlAltText
=
"ProcessingPath"
UniqueName
=
"ProcessingPath"
DataField
=
"Path"
HeaderText
=
"Path"
>
</
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
FilterControlAltText
=
"DueDate"
UniqueName
=
"DueDate"
DataField
=
"DueDate"
HtmlEncode
=
"false"
ItemStyle-Width
=
"10%"
HeaderText
=
"Due Date"
DataFormatString
=
"{0:dd MMMM yyyy HH:MM}"
>
</
telerik:GridBoundColumn
>
</
Columns
>
</
telerik:GridTableView
>
</
DetailTables
>
</
MasterTableView
>
</
telerik:RadGrid
>
<
asp:ObjectDataSource
ID
=
"odsDocument"
runat
=
"server"
SelectMethod
=
"GetDocumentsByOrderDetail"
TypeName
=
"ALBusinessLayer.TranslationOrderDetailDocument"
>
<
SelectParameters
>
<
asp:Parameter
Name
=
"OrderDetailID"
Type
=
"String"
/>
</
SelectParameters
>
</
asp:ObjectDataSource
>
<
asp:ObjectDataSource
ID
=
"odsParent"
runat
=
"server"
SelectMethod
=
"GetAllOrderDetailsByOrderID"
TypeName
=
"ALBusinessLayer.TranslationOrderDetail"
>
<
SelectParameters
>
<
asp:Parameter
Name
=
"orderId"
Type
=
"Int32"
/>
</
SelectParameters
>
</
asp:ObjectDataSource
>
Code behind:
protected void grdTransOrderDetails_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
{
if (TranslationOrderId > 0)
BindOrderDetailGrid(TranslationOrderId);
}
public void BindOrderDetailGrid(int orderId)
{
odsParent.SelectParameters["orderId"].DefaultValue = orderId.ToString();
grdTransOrderDetails.DataBind();
}
protected void grdTransOrderDetails_ItemCommand(object source, GridCommandEventArgs e)
{
string tName = e.Item.OwnerTableView.Name;
switch (e.CommandName)
{
case "Edit":
if (string.IsNullOrEmpty(tName))
{
////Edit Button of Translation order details grid has been clicked, First Level Grid
GridTableView grdTableView = e.Item.OwnerTableView.DetailTables[0];
string name = grdTableView.Name;
//foreach (GridNestedViewItem nestedViewItem in grdTableView.GetItems(GridItemType.NestedView))
foreach (GridDataItem nestedViewItem in grdTableView.Items)
{
// you should skip the items if not expanded, or tables not bound
//if (nestedViewItem.NestedTableViews.Length > 0)
//{
// // now you can access: nestedViewItem.NestedTableViews[0].Items, which will be the DataItems of this nested table
// // then make recursive call
// //LoopHierarchyRecursive(nestedViewItem.NestedTableViews[0]);
// // above [0] stands for the first table in the hierarchy, since Telerik RadGrid supports multiple tables at a level
//}
List<
string
> intDocIDs = new List<
string
>();
CheckBox chk = nestedViewItem.Cells[0].FindControl("chkItemSelect") as CheckBox;
if ((chk != null) && (chk.Checked))
{
////Store ID here
string id = nestedViewItem.GetDataKeyValue("TranslationOrderDetailDocumentID").ToString();
intDocIDs.Add(id);
}
}
}
else if (tName == "Documents")
{
////Edit Button of Documents grid has been clicked, Inner Grid
string strDocID = e.Item.OwnerTableView.DataKeyValues[e.Item.ItemIndex]["TranslationOrderDetailDocumentID"].ToString();
}
break;
case "Delete":
if (tName == "Documents")
{
//string strDetailID = e.Item.OwnerTableView.DataKeyValues[e.Item.ItemIndex]["TranslationOrderDetailID"].ToString();
object strDetailID = e.Item.OwnerTableView.ParentItem.GetDataKeyValue("TranslationOrderDetailID");
string strDocID = e.Item.OwnerTableView.DataKeyValues[e.Item.ItemIndex]["TranslationOrderDetailDocumentID"].ToString();
}
break;
}
}
//protected void grdTransOrderDetails_ItemCreated(object sender, GridItemEventArgs e)
//{
// //if (e.Item is GridNestedViewItem)
// //{
// // //e.Item.FindControl("InnerContainer").Visible = ((GridNestedViewItem)e.Item).ParentItem.Expanded;
// // if (e.Item.OwnerTableView.DetailTables != null)
// // {
// // if (e.Item.OwnerTableView.DetailTables[0].Name == "Documents")
// // {
// // TranslationOrderDetailDocument objTranslationOrderDetailDocument = null;
// // foreach (GridDataItem itm in e.Item.OwnerTableView.DetailTables[0].Items)
// // {
// // object id = itm.GetDataKeyValue("TranslationOrderDetailDocumentID");
// // objTranslationOrderDetailDocument = itm.DataItem as TranslationOrderDetailDocument;
// // }
// // e.Item.OwnerTableView.DetailTables[0].Columns[0].Visible = false;
// // }
// // }
// //}
//}
protected void grdTransOrderDetails_ItemDataBound(object sender, GridItemEventArgs e)
{
}
In the above code, I want to be able to get all the checkboxes placed in GridTemplateColumn and all selecte
d
DocumentID
s for a detail. what am I doing wrong here ?Thanks
0
Hello Tejas,
I went through your code and noticed that you are binding your grid twice. Once using declarative data sources (ObjectDataSource) and at the same time through the NeedDataSource event. Also, please keep in mind that you should never call the DataBind() method from inside the NeedDataSource handler or mix simple data-binding mode with advanced data-binding.
However, I suggest that you examine the following demos for more information about declarative data binding and programmatic binding of hierarchy grid and make the needed changes:
http://demos.telerik.com/aspnet-ajax/grid/examples/hierarchy/declarativerelations/defaultcs.aspx
http://demos.telerik.com/aspnet-ajax/grid/examples/programming/detailtabledatabind/defaultcs.aspx
Greetings,
Pavlina
the Telerik team
I went through your code and noticed that you are binding your grid twice. Once using declarative data sources (ObjectDataSource) and at the same time through the NeedDataSource event. Also, please keep in mind that you should never call the DataBind() method from inside the NeedDataSource handler or mix simple data-binding mode with advanced data-binding.
However, I suggest that you examine the following demos for more information about declarative data binding and programmatic binding of hierarchy grid and make the needed changes:
http://demos.telerik.com/aspnet-ajax/grid/examples/hierarchy/declarativerelations/defaultcs.aspx
http://demos.telerik.com/aspnet-ajax/grid/examples/programming/detailtabledatabind/defaultcs.aspx
Greetings,
Pavlina
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now
0
Tejas
Top achievements
Rank 1
answered on 03 Oct 2011, 07:48 PM
Hi Pavlina,
I could solve the problem.
Thanks for the solution.
I could solve the problem.
Thanks for the solution.