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

Get Value from a Control in RadGrid

6 Answers 256 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Dany V
Top achievements
Rank 1
Dany V asked on 19 Jun 2009, 09:48 PM

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

Sort by
0
Princy
Top achievements
Rank 2
answered on 22 Jun 2009, 06:49 AM
Hello Daniel,

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.
0
Dany V
Top achievements
Rank 1
answered on 22 Jun 2009, 05:11 PM
Hi Princy...thank you very much for your help...that's what I want to do, but can you please put the code in VB...
0
Princy
Top achievements
Rank 2
answered on 23 Jun 2009, 03:59 AM
Hello Daniel,

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.
0
Dany V
Top achievements
Rank 1
answered on 23 Jun 2009, 05:36 PM
Hello 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
0
Dany V
Top achievements
Rank 1
answered on 23 Jun 2009, 11:51 PM
Hello again!!...thanks but I've already solved my problem...
Daniel
Best!!
0
Satya Sahu
Top achievements
Rank 1
answered on 22 Mar 2010, 02:47 PM
Hi Princy,

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 
i am getting object reference error...

please suggest
Tags
Grid
Asked by
Dany V
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Dany V
Top achievements
Rank 1
Satya Sahu
Top achievements
Rank 1
Share this question
or