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

[Solved] Only first item reacts to grid_ItemCommand

2 Answers 112 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Soren Michelsen
Top achievements
Rank 1
Soren Michelsen asked on 16 Sep 2009, 07:25 AM
Hello,

I need to modify a server control from within my grid's ItemCommand event handler. The example below is simplified as much as I can.

Below, I  have an asp:label control inside a NestedItemView in my grid. The label's text property is set in my markup code.

When i expand the row (making the nested view visible), I want to modify the label.text property.

With the code below, when I expand the FIRST row in my grid, the label's text property is modified as it shoud. When I expand other rows, their labels' text properties are not modified.

I know this is a dumb example, but my real-world problem is too muddy to explain here. :-)


Protected Sub radGrid1_ItemCommand(ByVal source As ObjectByVal e As Telerik.Web.UI.GridCommandEventArgs) Handles radGrid1.ItemCommand 
 
        Dim nv As GridNestedViewItem = radGrid1.MasterTableView.GetItems(GridItemType.NestedView)(0) 
 
        Dim tmpLabel As Label = CType(nv.Controls(1).Controls(0).FindControl("lblTest"), Label) 
 
        tmpLabel.Text += "_bob" 
 
         
    End Sub 

Any help appreciated.

Jeppe Jespersen
Denmark

2 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 16 Sep 2009, 07:43 AM
Hi Jeppe,

Try out the following code snippet to achieve the desired scenario.

VB:
 
    Protected Sub RadGrid1_ItemCommand(ByVal source As ObjectByVal e As GridCommandEventArgs) 
        If e.CommandName = "ExpandCollapse" Then 
            Dim currentItem As GridDataItem = DirectCast(e.Item, GridDataItem) 
            Dim nv As GridNestedViewItem = DirectCast(currentItem.ChildItem, GridNestedViewItem) 
            Dim tmpLabel As Label = DirectCast(nv.FindControl("lblTest"), Label) 
            tmpLabel.Text += "_bob" 
        End If 
    End Sub 
 
 


Regards
Shinu
0
Soren Michelsen
Top achievements
Rank 1
answered on 16 Sep 2009, 08:07 AM
Shinu,

Close, but no cigar :-)

Here is my completed code, which calls an instance of a utility class that I made.
This instance returns a webChartViewer, that I then place in the nested view.

If e.CommandName = "ExpandCollapse" Then 
 
            Dim currentItem As GridDataItem = DirectCast(e.Item, GridDataItem) 
            Dim nv As GridNestedViewItem = DirectCast(currentItem.ChildItem, GridNestedViewItem) 
            Dim tmpLabel As Label = DirectCast(nv.FindControl("lblTest"), Label) 
 
            Dim myChartViewer As ChartDirector.WebChartViewer 
            myChartViewer = DirectCast(nv.FindControl("WebChartViewer1"), ChartDirector.WebChartViewer) 
 
            Dim wd As <...custom util object ...> 
            wd.GetChartWeb(myChartViewer, "MyChartTitle", tmpLabel.Text) 
            'getChartWeb parameters 
            '1: ChartDirector.WebChartViewer instance 
            '2: TitleText for the chart 
            '3: ID for records in database to be charted 
 
        End If 

Now what happens, is that the "last clicked" item displays my graph, but not the previously clicked items.
To see how it now (not) works, go here: http://www.stmtest.net/grid.wmv

I need all expanded rows to display the chart.

Jeppe
Tags
Grid
Asked by
Soren Michelsen
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Soren Michelsen
Top achievements
Rank 1
Share this question
or