Hi!!! I have a little problem with a control, the thing is that I want to obtain the value of a control inside a EditForm, so when I perform an Insert I get the value with this:
CType(RadGrid1.MasterTableView.GetInsertItem.FindControl("CheckBox1"), CheckBox)
But when I try to edit an item and get the value of that control, I can't...
Telerik.Web.UI.GridException
Message="Insert item is available only when grid is in insert mode."
Source="Telerik.Web.UI"
StackTrace:
at Telerik.Web.UI.GridTableView.GetInsertItem()
at _Default.ChBx_FallaSI_CheckedChanged(Object sender, EventArgs e) in C:\Documents and Settings\danivald\My Documents\WebRMAS\Default.aspx.vb:line 237
at System.Web.UI.WebControls.CheckBox.OnCheckedChanged(EventArgs e)
at System.Web.UI.WebControls.CheckBox.RaisePostDataChangedEvent()
at System.Web.UI.WebControls.CheckBox.System.Web.UI.IPostBackDataHandler.RaisePostDataChangedEvent()
at System.Web.UI.Page.RaiseChangedEvents()
at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
InnerException:
Please help me...!!!!
6 Answers, 1 is accepted
The InserItem will not be available in the EditMode as stated in the exception message. I suppose you are trying to access the checkbox in the update command or on the edit button click. If so, you can try out the following code snippets:
c# (to access the CheckBox on clicking the EditMode):
| protected void RadGrid1_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e) |
| { |
| if (e.Item is GridEditableItem && e.Item.IsInEditMode) |
| { |
| GridEditableItem editItem = (GridEditableItem)e.Item; |
| CheckBox chk = (CheckBox)editItem.FindControl("CheckBox1"); |
| } |
| } |
c#(to access the CheckBox in the UpdateCommand):
| protected void RadGrid1_UpdateCommand(object source, GridCommandEventArgs e) |
| { |
| GridEditableItem editedItem = (GridEditableItem)e.Item; |
| CheckBox chk = (CheckBox)editedItem.FindControl("CheckBox1"); |
| } |
Thanks
Princy.
Here's the VB code for the above mentioned scenario:
vb (to access the CheckBox on clicking the EditMode):
| Protected Sub RadGrid1_ItemDataBound(sender As Object, e As Telerik.Web.UI.GridItemEventArgs) |
| If TypeOf e.Item Is GridEditableItem AndAlso e.Item.IsInEditMode Then |
| Dim editItem As GridEditableItem = DirectCast(e.Item, GridEditableItem) |
| Dim chk As CheckBox = DirectCast(editItem.FindControl("CheckBox1"), CheckBox) |
| End If |
| End Sub |
vb (to access the CheckBox in the UpdateCommand):
| Protected Sub RadGrid1_UpdateCommand(source As Object, e As GridCommandEventArgs) |
| Dim editedItem As GridEditableItem = DirectCast(e.Item, GridEditableItem) |
| Dim chk As CheckBox = DirectCast(editedItem.FindControl("CheckBox1"), CheckBox) |
| End Sub |
You can make use of the following conversion tool to convert codes from C# to VB or vice versa:
Telerik Code Converter
Thanks
Princy.
That code converter is great, I didn't that there was something like that....now that I can access to the desire control, no I want to have access to it in other method, not just in the updateCommand or the ItemDataBound, I don't know how can I pass the arguments needed to implement the method...so, can you help me??
Best regards!
Daniel
Daniel
Best!!
i have got same issue.
| If TypeOf e.Item Is GridEditableItem Then |
| Dim grdRadRow As GridEditableItem = DirectCast(e.Item,GridEditableItem) |
| Dim txtstpos As TextBox = DirectCast(grdRadRow.FindControl("txtStartPos"), TextBox) |
| txtstpos.Enabled = False |
please suggest