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

ItemDataBound with autogenerated columns

3 Answers 74 Views
Grid
This is a migrated thread and some comments may be shown as answers.
renis cerga
Top achievements
Rank 1
renis cerga asked on 22 May 2010, 01:02 PM
Hi,

I have a dynamic pivot SQL query in a stored procedure, which returns a table. I used auto-generated columns, because that's the only way forward (number of columns and even column names changes). The first 2 columns are always the same, so i have the column name fixed. The rest are dynamic. Every cell has this format aaa|123. I need to split the string, put the first value in the cell and create an event on mouse click with the second value as parameter.

I saw i can get the value with ItemDataBound event, but it requires column name, not index. For example:
If TypeOf e.Item Is GridDataItem Then
            Dim dataItem As GridDataItem = DirectCast(e.Item, GridDataItem)
            dataItem.Item("ColumnX").Text = "Custom text"
        End If

What i need is something like

If TypeOf e.Item Is GridDataItem Then
            Dim dataItem As GridDataItem = DirectCast(e.Item, GridDataItem)
            dataItem.Item(3).Text = "Custom text"
        End If

And also i need to add a mouse click event in every cell

Please help!

Thank you!

3 Answers, 1 is accepted

Sort by
0
renis cerga
Top achievements
Rank 1
answered on 22 May 2010, 02:24 PM
I was able to find a solution as follows:

 
        Dim strtmp() As String 
        If TypeOf e.Item Is GridDataItem Then 
            For Each column As Telerik.Web.UI.GridColumn In RadGrid1.MasterTableView.RenderColumns 
                If column.UniqueName <> "ExpandColumn" And column.UniqueName <> "RowIndicator" And column.UniqueName <> "FixedCol1" And column.UniqueName <> "FixedCol2" Then 
                    Dim dataItem As GridDataItem = DirectCast(e.Item, GridDataItem) 
                    strtmp = dataItem.Item(column).Text.Split("|"
                    dataItem.Item(column).Text = strtmp(0) 
                End If 
            Next 
        End If 



The problem now is the mouseclick event. i tried adding the following row, but it doesn't worked:

dataItem.Item(column).Attributes.Add("onclick""CellClick('" + strtmp(1) + "');"


Of course i also added a simple JS function

    <script type="text/javascript"
        function CellClick(koefi_id) { 
            alert(koefi_id); 
        }    
    </script> 




Help!!!
0
renis cerga
Top achievements
Rank 1
answered on 23 May 2010, 07:54 PM
Strangely enough above example works fine in IE, but not in Firefox (indeed it works in a very very small region of TD)...

Help!!!!!
0
Veli
Telerik team
answered on 26 May 2010, 03:24 PM
Hello renis,

I tested your scenario in a project and it seems to work OK. You can successfully get table cells using GridDataItem.Item(Column) and attach an onclick client handler. If the problem persists, consider opening a regular support ticket where you can send us some test project we can run locally. In this way, we will be able to better assist you on this issue.

All the best,
Veli
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
Tags
Grid
Asked by
renis cerga
Top achievements
Rank 1
Answers by
renis cerga
Top achievements
Rank 1
Veli
Telerik team
Share this question
or