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

Insert non-databound row via code?

3 Answers 86 Views
Grid
This is a migrated thread and some comments may be shown as answers.
DonKitchen
Top achievements
Rank 1
DonKitchen asked on 24 Oct 2008, 07:07 PM
I have a scenario where I'm using the Radgrid with a datasource.  Depending on a certain condition in the grid's itemdatabound event, I'd like to insert/inject a new row into the row (item) collection.

For example, if I have a business condition, I want to add a placeholder row that says something like "Item skipped due to XXX".  I'm guessing that because the items are bound to the datasource, that it may be impossible to do this.  I am not using any sorting, grouping or filtering, so hopefully that helps since the grid is only getting bound once.

If I can't inject a row, can I some how show a grouping header for the rows and put my custom data in there?  It would almost be like re-purposing a group header when not using any grouping.

I hope this makes sense.  Thanks in advance for any suggestions!

3 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 27 Oct 2008, 12:38 PM
Hi,

A suggestion would be to put the desired row(eg after the 5th row)
 in edit mode and then design the edit form (Form Template ) accordingly to display a message(you can put a label in the edit form and then change the message according to the condition in the ItemDataBound event). This way the grid will appear to the user to have an unbound row in between the bound rows.

Thanks,
Princy
0
DonKitchen
Top achievements
Rank 1
answered on 28 Oct 2008, 01:34 PM
I'm having trouble figuring out how I would put my grid into edit mode for a specific row in the codebehind.  Here's the skeleton code where I make my decision and find the index of the current row.  How do I put the row before this one into edit mode?

Private Sub MyGridGrid_ItemDataBound(ByVal sender As ObjectByVal e As Telerik.Web.UI.GridItemEventArgs) 
 
        If TypeOf e.Item Is GridDataItem Then 
 
            Dim dataItem As GridDataItem = CType(e.Item, GridDataItem) 
             
            ::do stuff here:: 
 
            If mycondition = true Then 
                 
                Dim index As Integer = e.Item.ItemIndex 
                :: here's where I want to do it, for index - 1 (the row before this row) 
 
            End If 
             
            End If 
 
        End If 
 
    End Sub 

0
Shinu
Top achievements
Rank 2
answered on 29 Oct 2008, 04:59 AM
Hi,

Try the following line of code to edit the desired row.

VB:
    RadGrid1.Items(index - 1).Edit = True 

Thanks
Shinu.
Tags
Grid
Asked by
DonKitchen
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
DonKitchen
Top achievements
Rank 1
Shinu
Top achievements
Rank 2
Share this question
or