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

Popup Edit Resize Needed for Master & Detail

2 Answers 82 Views
Grid
This is a migrated thread and some comments may be shown as answers.
John
Top achievements
Rank 1
John asked on 18 Mar 2009, 01:28 PM
WIth a previous post I was able to get the following code to resize the columns on the popup editor. 

http://www.telerik.com/community/forums/aspnet-ajax/grid/radgrid-popup-editmode-field-width-issue.aspx

But now that I have added a detail table that also needs the columns resized in the popup editor so when the detail edit popup tries to appear the code abends trying to work on cells in the master grid.  How can I get the resizing to work with both master and detail popups without issue?

Thanks for help in advance!

John

 

protected void RGrd_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e)  
    {  
        if (e.Item is GridEditFormItem && e.Item.IsInEditMode)  
        {  
            GridEditFormItem editFormItem = (GridEditFormItem)e.Item;  
            foreach (GridColumn col in RGrd.MasterTableView.RenderColumns)  
            {  
                if (col.ColumnType == "GridBoundColumn")  
                {  
                    ((TextBox)editFormItem[col.UniqueName].Controls[0]).Width = Unit.Pixel(575);  
                }  
                if (col.ColumnType == "GridDropDownColumn")  
                {  
                    RadComboBox ddl = (RadComboBox)editFormItem[col.UniqueName].Controls[0];  
                    ddl.Width = Unit.Pixel(575);  
                }  
 
                if (col.ColumnType == "GridDateTimeColumn")  
                {  
                    RadDatePicker datepicker = (RadDatePicker)editFormItem[col.UniqueName].Controls[0];  
                    datepicker.Width = Unit.Pixel(575);  
                }               
 
            }  
        }   

2 Answers, 1 is accepted

Sort by
0
Accepted
Princy
Top achievements
Rank 2
answered on 19 Mar 2009, 05:26 AM
Hello John,

You can differentiate between the Master and Detail tables using their Name properties and then check for the OwnerTableViews Name in the ItemDataBound event of the grid and then resize the columns in the popup editor for the corresponding GridTableViews.
aspx:
<telerik:RadGrid ID="RadGrid2" runat="server" DataSourceID="SqlDataSource1" OnItemDataBound="RadGrid2_ItemDataBound" > 
      <MasterTableView EditMode="PopUp" DataSourceID="SqlDataSource1"  Name="Master"
       <DetailTables> 
        <telerik:GridTableView DataSourceID="SqlDataSource2" EditMode="PopUp" Name="Detail" runat="server" >            

cs:
if (e.Item is GridEditableItem && e.Item.IsInEditMode && e.Item.OwnerTableView.Name=="Master"
        { 
            GridEditFormItem editItem = (GridEditFormItem)e.Item; 
            foreach (GridColumn col in editItem.OwnerTableView.RenderColumns)   
            {   
                if (col.ColumnType == "GridBoundColumn")   
                {   
                    ((TextBox)editItem[col.UniqueName].Controls[0]).Width = Unit.Pixel(575);   
                }  
              //similar for other columns         
            } 
         } 
 
if (e.Item is GridEditableItem && e.Item.IsInEditMode && e.Item.OwnerTableView.Name=="Detail"
        { 
            GridEditFormItem editItem = (GridEditFormItem)e.Item; 
            foreach (GridColumn col in editItem.OwnerTableView.RenderColumns)   
            {   
                if (col.ColumnType == "GridBoundColumn")   
                {   
                    ((TextBox)editItem[col.UniqueName].Controls[0]).Width = Unit.Pixel(575);   
                }   
              //similar for other columns       
            } 
         } 
 
 

-Princy.
0
John
Top achievements
Rank 1
answered on 19 Mar 2009, 06:29 PM
Princy,

Thanks for the help it worked great!

John

Tags
Grid
Asked by
John
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
John
Top achievements
Rank 1
Share this question
or