I have a GridBoundColumn in a RadGrid that represents a primary key value and have its visible property set to "false" becuase it should not be editable. However, when clicking on 'edit' or 'add new record', the value becomes both visible and editable in the EditForm. I have tried setting the ReadOnly property to true, but this generates an error saying that I have to declare the variable. I need the value to be available in edit mode to ensure that the proper update. Does anyone know how I can make this happen?
5 Answers, 1 is accepted
0
Shinu
Top achievements
Rank 2
answered on 09 Jun 2008, 08:01 AM
Hi Jack,
Try setting the ReadOnly property for the GridboundColumn in the Aspx as shown below.
ASPX:
Shinu
Try setting the ReadOnly property for the GridboundColumn in the Aspx as shown below.
ASPX:
| <telerik:GridBoundColumn DataField="ProductName" HeaderText="ProductName" ReadOnly="true" Visible="true" SortExpression="ProductName" UniqueName="ProductName"></telerik:GridBoundColumn> |
Shinu
0
Jack
Top achievements
Rank 1
answered on 11 Jun 2008, 02:29 PM
Thanks Shinu, but it doesn't seem tp solve my problem. I have tried setting the ReadOnly property to true, but this generates an error saying that I have to declare the variable. I need the value to be available in edit mode to ensure that the proper update.
0
Shinu
Top achievements
Rank 2
answered on 12 Jun 2008, 05:36 AM
Hi,
I tried accessing the hidden field in the edit mode using the GetDataKeyValue property.
ASPX:
CS:
Thanks
Shinu.
I tried accessing the hidden field in the edit mode using the GetDataKeyValue property.
ASPX:
| <MasterTableView DataSourceID="SqlDataSource1" DataKeyNames="ProductName" > |
| <Columns> |
| <telerik:GridBoundColumn DataField="ProductName" HeaderText="ProductName" UniqueName="ProductName" ReadOnly="true" > |
| </telerik:GridBoundColumn> |
| <telerik:GridBoundColumn DataField="SupplierID" HeaderText="SupplierID" UniqueName="SupplierID"> |
| </telerik:GridBoundColumn> |
| <telerik:GridEditCommandColumn></telerik:GridEditCommandColumn> |
| </Columns> |
CS:
| protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e) |
| { |
| if ((e.Item is GridEditableItem) && (e.Item.IsInEditMode)) |
| { |
| GridEditableItem item = (GridEditableItem)e.Item; |
| string strKey = item.GetDataKeyValue("ProductName").ToString(); |
| } |
| } |
Thanks
Shinu.
0
Jack
Top achievements
Rank 1
answered on 12 Jun 2008, 03:19 PM
Hello,
I did a very sinmilar thing to solve the problem:
I did a very sinmilar thing to solve the problem:
If (TypeOf e.Item Is GridEditableItem AndAlso e.Item.IsInEditMode) Then
CType(e.Item, GridEditableItem)("item").Enabled = False
E
nd If
Thanks for all the help!
Jack
0
Princy
Top achievements
Rank 2
answered on 13 Jun 2008, 11:24 AM
Hi Jack,
You can also enable or disable the Textbox in the edit mode as shown below.
CS:
Princy.
You can also enable or disable the Textbox in the edit mode as shown below.
CS:
| protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e) |
| { |
| if ((e.Item is GridEditableItem) && (e.Item.IsInEditMode)) |
| { |
| GridEditableItem edititem = (GridEditableItem)e.Item; |
| TextBox txtbx = (TextBox)edititem["ProductName"].Controls[0]; |
| txtbx.Enabled = false; |
| } |
| } |
Princy.