This is a migrated thread and some comments may be shown as answers.

[Solved] Accessing Items in Hierarchical Grids

4 Answers 149 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Andrew
Top achievements
Rank 1
Andrew asked on 15 Jun 2009, 02:08 PM
Hi

I am trying to access image buttons within my Hierarchical Grid. Although i dont seem to be able to get hold of anything in order to access them. I am trying to do this within the DetailTableDataBind event.

 

protected void RadGrid1_DetailTableDataBind(object source, Telerik.Web.UI.GridDetailTableDataBindEventArgs e)

 

{

 

GridDataItem parentItem = (GridDataItem)e.DetailTableView.ParentItem;

 

 

 

 

 

string CID = parentItem.GetDataKeyValue("TblAVCID").ToString();

 

 

var avService = new AVService();

 

 

    
using
(TList<AV> avList = avService.GetByIntVisitCategory(Int32.Parse(CID.ToString())))

 

    {

        e.DetailTableView.DataSource = avList;

    }

((

ImageButton)parentItem["colDelete"].FindControl("imgDelete")).ImageUrl = txtImageDir + "16/data.gif";

 


 


I try binding to the imagebutton but this just errors out.

Any Help would be greatly appreciated.

Thanks

 

4 Answers, 1 is accepted

Sort by
0
Pavlina
Telerik team
answered on 15 Jun 2009, 02:55 PM
Hello Greg,

I suggest that you try accessing the  image buttons on ItemCreated/ItemDataBound event.
For more information about accessing cells and rows, please refer to this help article.

Kind regards,
Pavlina
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Andrew
Top achievements
Rank 1
answered on 15 Jun 2009, 03:43 PM
Hi

I think my problem may have been misunderstood.  I have looked at the link you sent , although i didnt see how i could incorporate this into what i was trying to do.
I think what i need is some sort of "onDetailTableItemCreated" method, like "ItemDataBound". As I dont see how i can traverse the hierarchical tables  and get the one i am currently in in order to do something like 

if (e.Item is GridDataItem)  
{  
var iObject = (GridDataItem)e.Item;  
iObject["colExport"].FindControl("imgExport")).ImageUrl = "" 

Thanks



0
Accepted
Princy
Top achievements
Rank 2
answered on 16 Jun 2009, 08:00 AM
Hello Greg,

You can set the Name property of the DetailTable and then in the ItemDataBound/ItemCreated event of the grid check for the name of the ownertableview and then traverse through the detail table items. Check out the code below to understand better:
aspx:
 <telerik:RadGrid ID="RadGrid2"  runat="server" DataSourceID="SqlDataSource1"  OnItemDataBound="RadGrid2_ItemDataBound" >       
        <MasterTableView  DataSourceID="SqlDataSource1" Name="Master">       
          <DetailTables>        
             <telerik:GridTableView  DataSourceID="SqlDataSource2"  Name="Detail" runat="server" > 

c#:
 protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e) 
    { 
       if (e.Item is GridDataItem && e.Item.OwnerTableView.Name == "Detail"
        { 
            GridDataItem item = (GridDataItem)e.Item;              
            ((ImageButton)item["colExport"].FindControl("imgExport")).ImageUrl = ""  
        } 
    } 
You can also refer to the following help article for more details on distinguishing between grid rows in a hierarchial grid:
Distinguish grid rows in hierarchy on ItemCreated/ItemDataBound



Thanks
Princy.
0
Andrew
Top achievements
Rank 1
answered on 16 Jun 2009, 08:38 AM
Hi

Thanks very much, that worked brilliantly.

Thanks again
Tags
Grid
Asked by
Andrew
Top achievements
Rank 1
Answers by
Pavlina
Telerik team
Andrew
Top achievements
Rank 1
Princy
Top achievements
Rank 2
Share this question
or