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

Set Edit mode property in ItemDataBound event handler

2 Answers 147 Views
Grid
This is a migrated thread and some comments may be shown as answers.
cheburek
Top achievements
Rank 1
cheburek asked on 25 Jan 2010, 12:57 PM
Hello
I need to set grid rows to edit mode base on there model data. For this purpose I use ItemDataBound event as following

Private Sub weldsGrid_ItemDataBound(ByVal sender As ObjectByVal e As Telerik.Web.UI.GridItemEventArgs) Handles weldsGrid.ItemDataBound 
    If (e.Item.ItemType = Telerik.Web.UI.GridItemType.Item OrElse _ 
        e.Item.ItemType = Telerik.Web.UI.GridItemType.AlternatingItem OrElse _ 
        e.Item.ItemType = GridItemType.EditItem) Then 
 
      If (e.Item.ItemIndex > -1) Then 
        Dim row = CType(CType(e.Item.DataItem, DataRowView).Row, MyDataSet.DataSetRow) 
        e.Item.Edit = row.IsActive() 
      End If 
 
    End If 
  End Sub 

And it set up the first time row to edit mode but then if I make grid rebind with another filter in my stored procedure and load other data incorrect row will be editable (on the same place as was item before - it passed to ItemDataBound with EditItem type and code set Item.Edit to false). After that any postback cause viewstate load exception
Failed to load viewstate. The control tree into which viewstate is being loaded must match the control tree that was used to save viewstate during the previous request. For example, when adding controls dynamically, the controls added during a post-back must match the type and position of the controls added during the initial request.
   at System.Web.UI.Control.LoadViewStateRecursive(Object savedState)   at System.Web.UI.Control.LoadChildViewStateByIndex(ArrayList childState)   at System.Web.UI.Control.LoadViewStateRecursive(Object savedState)   at System.Web.UI.Control.LoadChildViewStateByIndex(ArrayList childState)   at System.Web.UI.Control.LoadViewStateRecursive(Object savedState)   at System.Web.UI.Control.LoadChildViewStateByIndex(ArrayList childState)   at System.Web.UI.Control.LoadViewStateRecursive(Object savedState)   at System.Web.UI.Control.LoadChildViewStateByIndex(ArrayList childState)   at System.Web.UI.Control.LoadViewStateRecursive(Object savedState)   at System.Web.UI.Control.LoadChildViewStateByIndex(ArrayList childState)   at System.Web.UI.Control.LoadViewStateRecursive(Object savedState)   at System.Web.UI.Control.LoadChildViewStateByIndex(ArrayList childState)   at System.Web.UI.Control.LoadViewStateRecursive(Object savedState)   at System.Web.UI.Control.LoadChildViewStateByIndex(ArrayList childState)   at System.Web.UI.Control.LoadViewStateRecursive(Object savedState)   at System.Web.UI.Control.LoadChildViewStateByIndex(ArrayList childState)   at System.Web.UI.Control.LoadViewStateRecursive(Object savedState)   at System.Web.UI.Control.LoadChildViewStateByIndex(ArrayList childState)   at System.Web.UI.Control.LoadViewStateRecursive(Object savedState)   at System.Web.UI.Control.LoadChildViewStateByIndex(ArrayList childState)   at System.Web.UI.Control.LoadViewStateRecursive(Object savedState)   at System.Web.UI.Control.LoadChildViewStateByIndex(ArrayList childState)   at System.Web.UI.Control.LoadViewStateRecursive(Object savedState)   at System.Web.UI.Control.LoadChildViewStateByIndex(ArrayList childState)   at System.Web.UI.Control.LoadViewStateRecursive(Object savedState)   at System.Web.UI.Control.LoadChildViewStateByIndex(ArrayList childState)   at System.Web.UI.Control.LoadViewStateRecursive(Object savedState)   at System.Web.UI.Page.LoadAllState()   at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)

Is it possible somehow to manipulate with row Edit mode from ServerSide using model data?
Thanks in advance

2 Answers, 1 is accepted

Sort by
0
Iana Tsolova
Telerik team
answered on 28 Jan 2010, 08:51 AM
Hi cheburek,

In order to achieve your goal, I suggest that you handle the grid PreRender event. There you can loop through the grid items and check what of them apply to your condition. Then after setting the desired items in edit mode, you will need to Rebind() the grid.

Give it a try and let me know if any issues arise.

Greetings,
Iana
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
cheburek
Top achievements
Rank 1
answered on 12 Sep 2010, 12:35 PM

I cannot check that solution for now because it is quite old piece of code.

On that moment I found another workaround - rejected idea of using view/edit grid modes, added to view mode readonly and edit controls and manually set their Visible property depending on required condition in ItemDataBound event handler. This way does not require grid rebinding.

Thanks a ton for your help anyway

Tags
Grid
Asked by
cheburek
Top achievements
Rank 1
Answers by
Iana Tsolova
Telerik team
cheburek
Top achievements
Rank 1
Share this question
or