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

Auto Expanding specific rows on load

1 Answer 182 Views
Grid
This is a migrated thread and some comments may be shown as answers.
twRoss
Top achievements
Rank 1
twRoss asked on 12 Aug 2011, 11:33 AM

I have a Rad grid bound to a sqldatasources  using hierarchical Declarative relations which works fine. However I would like to have only specific rows expanded on load based on the value in one of the columns of the master table. I have tried the following code which does target the correct rows but does not expand them on load.

Protected Sub RadGrid1_ItemDataBound(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridItemEventArgs) Handles RadGrid1.ItemDataBound
        If (TypeOf e.Item Is GridDataItem) Then
            If (e.Item.OwnerTableView.DataSourceID = "SqlDSmaster") Then
                'process requested operations
                Dim DataItem As GridDataItem = CType(e.Item, GridDataItem)
 
                If DataItem("Status").Text = "Hasdetailrows" Then
                    DataItem.BackColor = Drawing.Color.Red
                    DataItem.FireCommandEvent("ExpandCollapse", DataItem)
                    DataItem.Expanded = True
                End If
 
            End If
 
        End If
    End Sub




Any help would be appreciated.
Kind Regards
Ross

1 Answer, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 12 Aug 2011, 12:05 PM
Hello Ross,

Try the following code snippet to achieve your scenario.
C#:
public partial class RadGrid_hierarchy3leveldeclarative : System.Web.UI.Page
{
   //Global variables
  int[] index = new int[10];
  int i=0;
  protected void RadGrid1_PreRender(object sender, EventArgs e)
  {
      if (index.Count() > 0)
      {
          for (int temp = 0; temp < index.Count();temp++)
          {
            int val=index[temp];
            RadGrid1.MasterTableView.Items[val].Expanded = true;
          }
      }
  }
  protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
  {
      if (e.Item is GridDataItem)
      {
          if (e.Item.OwnerTableView.DataSourceID == "SqlDataSource1")
          {
              //process requested operations
              GridDataItem DataItem = (GridDataItem)e.Item;
              if (DataItem["Status"].Text == "Hasdetailrows")
              {
                  DataItem.BackColor = System.Drawing.Color.Red;
                  index[i++] = DataItem.ItemIndex;     
              }
          }
      }
  }
}

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