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

[Solved] How to retain the detail table values after selected index changed event fire

4 Answers 254 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Kevin
Top achievements
Rank 1
Kevin asked on 12 Jan 2010, 06:45 PM

Folks,

I am trying to retain the values in a detail grid after a griddropdowncolumn event fire (selectedindexchanged event ). I am extracting the values (current cell values) of the grid in a session variable and changing some properties for a column depending on the selected value in dropdown in the selectedindexchanged event (then I am rebinding the grid to see the effects of changed properties). Then in grid prerender event I am trying to set the cell values from the session variable, Here comes the problem, I am unable to find the detail grid items to set the cell values.

I am binding the grid on the server (using needdatasource event and detailtablebind events).

For your reference, I have included my selectedindexchanged event and grid prerender events here

Private Sub List_SelectedIndexChanged(ByVal sender As ObjectByVal e As RadComboBoxSelectedIndexChangedEventArgs)  
 
            Dim editedItem As GridEditableItem = CType(CType(sender, RadComboBox).NamingContainer, GridEditableItem)  
            Dim ddlChsnMthd As RadComboBox = CType(editedItem("CHSN_MTHD_ID").Controls(0), RadComboBox)  
            Dim insertItem As GridDataItem = DirectCast(CType(sender, RadComboBox).NamingContainer, GridDataItem)  
            Dim insertVals As Hashtable = New Hashtable  
 
            RadGrid1.MasterTableView.ExtractValuesFromItem(insertVals, insertItem)  
            Session("insertvals") = insertVals  
 
            If ddlChsnMthd.SelectedValue = 4 Then 
                RadGrid1.MasterTableView.DetailTables.Item(0).Columns.Item(9).Visible = True 
            Else 
                RadGrid1.MasterTableView.DetailTables.Item(0).Columns.Item(9).Visible = False 
            End If 
 
            RadGrid1.MasterTableView.Rebind()  
 
End Sub

 

Protected Sub RadGrid1_PreRender(ByVal sender As ObjectByVal e As System.EventArgs) Handles RadGrid1.PreRender     
    
    
           If Not Session("insertvals"Is Nothing AndAlso RadGridTransCalc.MasterTableView.DetailTables.Item(0).IsItemInserted Then    
                Dim insertvals As Hashtable = CType(Session("insertvals"), Hashtable)     
                Dim insertItem As GridEditableItem = DirectCast(RadGridTransCalc.MasterTableView.DetailTables.Item(0).GetInsertItem(), GridEditableItem)     
                If Not insertvals("ID"Is Nothing Then TryCast(insertItem("ID").Controls(0), RadComboBox).SelectedValue = insertvals("ID")     
                If Not insertvals("CALC_DATE"Is Nothing Then TryCast(insertItem("CALC_DATE").Controls(0), RadDatePicker).SelectedDate = CDate(insertvals("CALC_DATE"))     
                If Not insertvals("STRT_TIME"Is Nothing Then TryCast(insertItem("STRT_TIME").Controls(0), RadTimePicker).SelectedDate = CDate(insertvals("STRT_TIME"))     
                If Not insertvals("END_TIME"Is Nothing Then TryCast(insertItem("END_TIME").Controls(0), RadTimePicker).SelectedDate = CDate(insertvals("END_TIME"))     
                If Not insertvals("COND_ID"Is Nothing Then TryCast(insertItem("COND_ID").Controls(0), RadComboBox).SelectedValue = insertvals("COND_ID")     
                If Not insertvals("MTHD_ID"Is Nothing Then TryCast(insertItem("MTHD_ID").Controls(0), RadComboBox).SelectedValue = insertvals("MTHD_ID")     
          End If    
 
End Sub   
 

Does anyone came across this scenario, please help.

Thanks,

Kevin

4 Answers, 1 is accepted

Sort by
0
Mira
Telerik team
answered on 15 Jan 2010, 12:45 PM
Hi Kevin,

I have reviewed your code and I recommend that you remove the call to the Rebind() method from the SelectedIndexChanged event handler of the drop down.
You may traverse the edited items on PreRender using the EditItems property of the RadGrid as well.

Please give these suggestions a try and let me know how it goes.

Greetings,
Mira
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
Kevin
Top achievements
Rank 1
answered on 02 Feb 2010, 04:19 PM
Thanks for the reply Mira

I am changing the column properties on selectedindexchanged event, hence i am rebinding the grid to see the changes.
I am seeing something starnge here, my detail grid is in editable mode, when I cahne the dropdown my selectedindexchanged event is fired, I am changing the properties of the columns (to make readonly to be editable...) based on the dropdown selection but the IsItemInserted Property for the child grid always returning FALSE in the grid prerender event (same is the case even removing the rebind in selectedindexchanged event).

below is the code I am using in grid prerender event

Dim firstDetail As GridTableView = RadGrid1.MasterTableView.Items(0).ChildItem.NestedTableViews(0)  
 
            If firstDetail.IsItemInserted Then  
                ' Do Something  
            End If 

Please Help


--
Kevin
0
Iana Tsolova
Telerik team
answered on 05 Feb 2010, 08:08 AM
Hello Kevin,

What is the value of the IsItemInserted property in the SelectedIndexChanged event, before you apply the columns changes?
Additionally, it would be great if you can prepare a stripped version of your scenario and send us a runnable project replicating the faced problem. Thus we could do our best to provide a proper resolution for you.

All the best,
Iana
the Telerik team

Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Follow the status of features or bugs in PITS and vote for them to affect their priority.
0
Kevin
Top achievements
Rank 1
answered on 05 Feb 2010, 05:20 PM
ooh finally I am able to set the values for detail grid after the selectedindexchanged event by traversing thru the child items in the grid pre render event, below is the code I am using to accomplish this

I am setting session("Vals") in the selectedindexchangedevent and using it to set the values

thanks for the suggestions

For Each item As GridDataItem In RadGridTransCalc.Items  
    If item.OwnerTableView.Name = "DetailTB" Then  
       If Not Session("Vals") Is Nothing AndAlso item.IsInEditMode Then  
          Dim insertvals As Hashtable = CType(Session("Vals"), Hashtable)  
          If Not Vals("ID") Is Nothing Then TryCast(item("ID").Controls(0), RadComboBox).SelectedValue = Vals("ID")  
          If Not Vals("CALC_DATE") Is Nothing Then TryCast(item("CALC_DATE").Controls(0), RadDatePicker).SelectedDate = CDate(Vals("CALC_DATE"))  
          If Not Vals("START_TIME") Is Nothing Then TryCast(item("START_TIME").Controls(0), RadTimePicker).SelectedDate = CDate(Vals("START_TIME"))  
          If Not Vals("END_TIME") Is Nothing Then TryCast(item("END_TIME").Controls(0), RadTimePicker).SelectedDate = CDate(Vals("END_TIME"))  
          If Not Vals("COND_ID") Is Nothing Then TryCast(item("COND_ID").Controls(0), RadComboBox).SelectedValue = Vals("COND_ID")  
          If Not Vals("MTHD_ID") Is Nothing Then TryCast(item("MTHD_ID").Controls(0), RadComboBox).SelectedValue = Vals("MTHD_ID")  
          If Not Vals("VOL1") Is Nothing Then TryCast(item("VOL1").Controls(0), TextBox).Text = Vals("VOL1")  
          If Not Vals("VOL2") Is Nothing Then TryCast(item("VOL2").Controls(0), TextBox).Text = Vals("VOL2")  
          If Not Vals("VOL3") Is Nothing Then TryCast(item("VOL3").Controls(0), TextBox).Text = Vals("VOL3")  
        End If  
       End If  
Next 

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