Hi
I have a RadGrid that I fill with a dynamically generated DataTable, like this :
Column 1 contains text (1 Level, 2 Level, 3 Level etc), depending on NoOfRows. Column 2 is a GridDropDownColumn, with the items in the dropdowns is filled from the DB.
I want to make Column 2 editable, while keeping Column 1 in read-only mode. How can I do this?
I have a RadGrid that I fill with a dynamically generated DataTable, like this :
DataTable ds = new DataTable(); |
DataColumn dc1 = new DataColumn("Column 1"); |
DataColumn dc2 = new DataColumn("Column 2"); |
ds.Columns.Add(dc1); |
ds.Columns.Add(dc2); |
for (int i = 0; i < Convert.ToInt16(NoOfRows); i++) |
{ |
DataRow dr = ds.NewRow(); |
dr["Column 1"] = i.ToString + " Level"; |
ds.Rows.Add(dr); |
} |
RadGrid1.DataSource = ds; |
RadGrid1.DataBind(); |
Column 1 contains text (1 Level, 2 Level, 3 Level etc), depending on NoOfRows. Column 2 is a GridDropDownColumn, with the items in the dropdowns is filled from the DB.
I want to make Column 2 editable, while keeping Column 1 in read-only mode. How can I do this?
7 Answers, 1 is accepted
0
Hello Marcel,
Try to modify the code as follows:
Regards,
Daniel
the Telerik team
Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Try to modify the code as follows:
DataTable ds = new DataTable(); |
DataColumn dc1 = new DataColumn("Column 1"); |
DataColumn dc2 = new DataColumn("Column 2"); |
dc1.ReadOnly = true; |
ds.Columns.Add(dc1); |
ds.Columns.Add(dc2); |
for (int i = 0; i < Convert.ToInt16(NoOfRows); i++) |
{ |
DataRow dr = ds.NewRow(); |
dr["Column 1"] = i.ToString() + " Level"; |
ds.Rows.Add(dr); |
} |
RadGrid1.DataSource = ds; |
RadGrid1.DataBind(); |
Regards,
Daniel
the Telerik team
Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0

CBARS
Top achievements
Rank 2
answered on 09 Oct 2008, 08:41 AM
Hi
I've tried setting the DataColumn's ReadOnly property to true, but it's still editable on the page.
Can it be because of the way I make the one column editable? I'm capturing the Page_Render event, like so :
I know this makes all the GridDataItems editable, but shouldn't the ReadOnly property be preventing it from being edited? Is GridDataItem.Edit supposed to override the ReadOnly property?
I've tried setting the DataColumn's ReadOnly property to true, but it's still editable on the page.
Can it be because of the way I make the one column editable? I'm capturing the Page_Render event, like so :
foreach (Telerik.Web.UI.GridDataItem item in grdIdentifiers.Items) |
{ |
item.Edit = true; |
} |
grdIdentifiers.Rebind(); |
I know this makes all the GridDataItems editable, but shouldn't the ReadOnly property be preventing it from being edited? Is GridDataItem.Edit supposed to override the ReadOnly property?
0

CBARS
Top achievements
Rank 2
answered on 09 Oct 2008, 12:14 PM
I've tried the code here :
in other words, adding the 'is GridEditableItem' condition, but my first column is still editable.
protected void Page_PreRender(object sender, EventArgs e) |
{ |
foreach (Telerik.Web.UI.GridDataItem item in grdIdentifiers.Items) |
{ |
if (item is Telerik.Web.UI.GridEditableItem) |
{ |
Telerik.Web.UI.GridEditableItem editableItem = item as |
Telerik.Web.UI.GridDataItem; |
editableItem.Edit = true; |
} |
} |
grdIdentifiers.Rebind(); |
} |
in other words, adding the 'is GridEditableItem' condition, but my first column is still editable.
0
Hello Marcel,
As you properly noticed e.Item.Edit = "true" is causing the mentioned behavior.
You can try this approach if it's appropriate for your scenario:
Best regards,
Daniel
the Telerik team
Check out Telerik Trainer, the state of the art learning tool for Telerik products.
As you properly noticed e.Item.Edit = "true" is causing the mentioned behavior.
You can try this approach if it's appropriate for your scenario:
protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e) |
{ |
GridEditFormItem item = e.Item as GridEditFormItem; |
if (item != null && e.Item.IsInEditMode) |
{ |
(item["Name"].Controls[0] as TextBox).Enabled = false; |
} |
} |
Best regards,
Daniel
the Telerik team
Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0

CBARS
Top achievements
Rank 2
answered on 15 Oct 2008, 10:31 AM
Hi Daniel
I've just about tried every combination of Pre_Render and Item_Created events to try and keep the one column read-only, while the other is editable. The previous suggestion doesn't work, as the combination of Item.Edit and disabling the textbox control in the cell, once again either makes everything read-only, or everything editable.
Is there a standard way of doing this? Do you have a complete example?
I've just about tried every combination of Pre_Render and Item_Created events to try and keep the one column read-only, while the other is editable. The previous suggestion doesn't work, as the combination of Item.Edit and disabling the textbox control in the cell, once again either makes everything read-only, or everything editable.
Is there a standard way of doing this? Do you have a complete example?
0
Accepted
Hello Marcel,
I created two simple examples - for both InPlace and EditForms modes.
Let us know when you test them.
Best regards,
Daniel
the Telerik team
Check out Telerik Trainer, the state of the art learning tool for Telerik products.
I created two simple examples - for both InPlace and EditForms modes.
Let us know when you test them.
Best regards,
Daniel
the Telerik team
Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0

CBARS
Top achievements
Rank 2
answered on 20 Oct 2008, 01:25 PM
Thanks Daniel.
I've tried the InPlace mode, works perfect.
I've tried the InPlace mode, works perfect.