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

Problems with RadGrid

2 Answers 66 Views
Grid
This is a migrated thread and some comments may be shown as answers.
VS
Top achievements
Rank 1
VS asked on 01 Sep 2008, 07:26 AM

Hi,

I have a grid with a column as,

<rad:GridBoundColumn DataField="ProcessDescription" EditFormColumnIndex="1" HeaderText="Description" UniqueName="Description">
                    <HeaderStyle Font-Bold="true" />
                </rad:GridBoundColumn>

Now when i tried to make certain columns as disabled in edit mode in the ItemDatabound event, its working fine but when i move the cursor on top of that disabled field, i get a javascript error which says
My aim is to just display it in a label with the text in grid.

I tried disabling as below,

if (e.Item is GridEditableItem && ((GridEditableItem)e.Item).IsInEditMode)
            {
                GridEditableItem editItem = (GridEditableItem)e.Item;

                TextBox txtDesc = (TextBox)editItem["Description"].Controls[0];
                txtDesc.Enabled = false;
            }

Similar to this i have a date column as
 <rad:GridDateTimeColumn DataField="EndDate" EditFormColumnIndex="0" DataFormatString="{0:d}" meta:resourcekey="GridTemplateColumnResource2">
                    <HeaderStyle Font-Bold="true" />
                </rad:GridDateTimeColumn>    

When i edit mode, i need to display only the date in a label and not in a date control. I want to make it not to be visible when in insert mode.

"Sys.ArgumentException: Value must be a DOm element. Parameter name:element".

How to solve this or Is there a better method to make certain columns in a grid as disabled when in editmode.

In Insert mode ( i mean when i click ' Add new record' link at the top of the grid), i want to make this column as not visible. How will i be able to achieve this?

Regards

Sujith

2 Answers, 1 is accepted

Sort by
0
Vlad
Telerik team
answered on 01 Sep 2008, 09:08 AM
Hi Sujith,

This is general problem in Microsoft ASP.NET AJAX. Please check this thread for more info:
http://forums.asp.net/p/1151199/2496957.aspx

Kind regards,
Vlad
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Princy
Top achievements
Rank 2
answered on 01 Sep 2008, 11:59 AM
Hi Sujith,

Try with the following code snippet to make the GridDateTimeColumn ReadOnly only in Insert mode.

ASPX:
<telerik:GridDateTimeColumn UniqueName="DateCol" DataField="Date"    HeaderText="DateCol" ></telerik:GridDateTimeColumn> 
                 

CS:
 protected void RadGrid1_PreRender(object sender, EventArgs e) 
    { 
        foreach (GridItem item in RadGrid1.MasterTableView.Items) 
        { 
 
            if ((item.OwnerTableView.IsItemInserted) && (!item.IsInEditMode)) 
            { 
                foreach (GridColumn col in RadGrid1.MasterTableView.RenderColumns) 
                { 
                    if ((col.UniqueName == "DateCol") && (col.ColumnType == "GridDateTimeColumn")) 
                    { 
                        GridDateTimeColumn DateCol = (GridDateTimeColumn)col; 
                        DateCol.ReadOnly = true
                    } 
                } 
            } 
            else if ((item.Edit) && (!item.OwnerTableView.IsItemInserted)) 
            { 
                if (item is GridEditableItem) 
                { 
                    GridEditableItem edititem = (GridEditableItem)item; 
                    foreach (GridColumn col in RadGrid1.MasterTableView.RenderColumns) 
                    { 
                        if ((col.UniqueName == "DateCol") && (col.ColumnType == "GridDateTimeColumn")) 
                        { 
                            GridDateTimeColumn DateCol = (GridDateTimeColumn)col; 
                            DateCol.ReadOnly = false
                        } 
 
                    } 
 
 
                } 
 
            } 
 
 
        } 
        RadGrid1.Rebind(); 
    } 

 Code to replace the RadDatePicker of the GridDateTimeColumn with a label in the edit mode.

CS:
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e) 
    { 
        if ((e.Item is GridEditableItem) && (e.Item.IsInEditMode)&&(!e.Item.OwnerTableView.IsItemInserted)) 
        { 
            GridEditableItem edititem = (GridEditableItem)e.Item; 
            RadDatePicker pkr = (RadDatePicker)edititem["DateCol"].Controls[0]; 
            Label lbl = new Label(); 
            lbl.ID = "Label1"
            lbl.Text = pkr.DbSelectedDate.ToString(); 
            edititem["DateCol"].Controls.Clear(); 
            edititem["DateCol"].Controls.Add(lbl); 
        } 
    } 


Thanks
Princy.
Tags
Grid
Asked by
VS
Top achievements
Rank 1
Answers by
Vlad
Telerik team
Princy
Top achievements
Rank 2
Share this question
or