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

Header caption

7 Answers 298 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Jean-Marc
Top achievements
Rank 1
Jean-Marc asked on 29 Sep 2011, 11:13 AM
Hello,
I have the same problem of this thread
http://www.telerik.com/community/forums/aspnet-ajax/grid/column-names-are-shown-instead-of-column-captions.aspx

I did as explained there, it works.
Unfortunately, as i click on a row, header captions go back to their colum names. How can i solve it?


Beside, is there a way to have header text vertically instead fo horizontally, I mean from top do bottom
Thank you

7 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 29 Sep 2011, 12:42 PM
Hello Jean,

You could attach the ItemCommand and call the Rebind method which worked as expected at my end. Here is the sample code which I tried.
C#:
public partial class RadGrid_simpledata : System.Web.UI.Page
{
    DataTable ds1 = new DataTable();
                
    protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
    {
       if (e.Item is GridHeaderItem)
        {
         GridHeaderItem it = e.Item as GridHeaderItem;
         int i = 0;
         foreach ( GridColumn col in RadGrid1.MasterTableView.AutoGeneratedColumns)
           {
               it[col.UniqueName].Text = ds1.Columns[i].Caption;
           }
        }
    }
    protected void RadGrid1_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
    {
        LoadData();
    }
    protected void RadGrid1_ItemCommand(object sender, GridCommandEventArgs e)
    {
        if (e.CommandName == "RowClick")
        {
          RadGrid1.Rebind();
        }
    }
   private void LoadData()
    {
        SqlConnection con = new SqlConnection(WebConfigurationManager.ConnectionStrings["NorthwindConnectionString"].ConnectionString);
        SqlCommand cmd1 = new SqlCommand("select EmployeeID,LastName,FirstName from Employees", con);
        SqlDataAdapter ad1 = new SqlDataAdapter(cmd1);
       
        ad1.Fill(ds1);
        RadGrid1.DataSource = ds1; ;
        ds1.Columns[0].Caption = "Column1";
        ds1.Columns[1].Caption = "Column2";
        ds1.Columns[2].Caption = "Column3";
    }   
}

Thanks,
Shinu.
0
Jean-Marc
Top achievements
Rank 1
answered on 29 Sep 2011, 01:35 PM
Yes! thank you

i guess there is no way for the second point,  the vertical header, right?
0
Jean-Marc
Top achievements
Rank 1
answered on 29 Sep 2011, 05:07 PM
I've added a detailTable, it happens now that expanding a row to its child I have this scenario

itemDataBound fires
(I check now e.Item.OwnerTableView.Name)
1. has the name of masterTableView everything is ok
2. has the name of detailView header captions of the masterTableView are not set (uniqueName is shown)

Help please
0
Accepted
Princy
Top achievements
Rank 2
answered on 30 Sep 2011, 06:32 AM
Hello Jean-Marc,

You can set vertical text in header by using any of the 3 methods mentioned below.
Method 1:
The easiest method is try setting the HeaderText as shown below
aspx:
<telerik:GridBoundColumn HeaderText="N<br />a<br />m<br />e">
</telerik:GridBoundColumn>
Method2:
Try setting the markup and custom CSS in HeaderStyle
aspx:
<telerik:GridBoundColumn>
 .   .  .  .
   <HeaderStyle CssClass="rmText" />
</telerik:GridBoundColumn>
CSS:
.rmText
{
  writing-mode: tb-rl !important;
  filter: flipV flipH !important;
  display: table !important;
  -moz-transform: rotate(-90deg) !important;
}
Method3:
Use GridTemplateColumns with images in the HeaderTemplate. The images will contain the flipped vertical text.

Thanks,
Princy.
0
Shinu
Top achievements
Rank 2
answered on 03 Oct 2011, 07:38 AM
Hello Jean,

I also faced the same issue and was able to over come this by setting the Headertext  again in the RowClick event. Here is the sample code which I tried.
C#:
protected void RadGrid1_ItemCommand(object sender, GridCommandEventArgs e)
 {
   if (e.CommandName == "RowClick")
    {
     setHeading();
    }
 }
public void setHeading()
 {
   foreach (GridDataItem item in RadGrid1.MasterTableView.Items)
     {
        GridTableView second_tableView = (GridTableView)item.ChildItem.NestedTableViews[0];
        GridHeaderItem it = second_tableView.GetItems(GridItemType.Header)[0] as GridHeaderItem;
        int i = 0;
        foreach (GridColumn col in second_tableView.Columns)
         {
           it[col.UniqueName].Text = myDataTable.Columns[i].Caption;
           i++;
         }
     }
  }

Thanks,
Shinu.
0
Jean-Marc
Top achievements
Rank 1
answered on 03 Oct 2011, 03:31 PM
Yes right, clicking on the row makes the job
my common scenario is clicking on the arrow to expand/collapse childitems
I add this case too

 If (e.CommandName = "ExpandCollapse") Then
                Call setHeading()
End If

gives me a System.IndexOutOfRangeException error in setHeading function
0
Shinu
Top achievements
Rank 2
answered on 04 Oct 2011, 06:38 AM
Hello Jean,

I have tried the same and that worked as expected at my end. My grid contains a Master and Detail table. Here is the code which I tried.
C#:
protected void RadGrid1_DetailTableDataBind(object sender, GridDetailTableDataBindEventArgs e)
    {
        GridDataItem parentItem = (GridDataItem)e.DetailTableView.ParentItem;
        string CustomerID = parentItem.GetDataKeyValue("CustomerID").ToString();
        e.DetailTableView.DataSource = GetDataTable("SELECT * FROM Orders WHERE CustomerID = '" + CustomerID + "'");          
    }
public DataTable GetDataTable(string query)
    {
        String ConnString = ConfigurationManager.ConnectionStrings["NorthwindConnectionString"].ConnectionString;
        SqlConnection conn = new SqlConnection(ConnString);
        SqlDataAdapter adapter = new SqlDataAdapter();
        adapter.SelectCommand = new SqlCommand(query, conn);
 
        conn.Open();
        try
        {
            adapter.Fill(myDataTable);
            //setting datatable caption
            myDataTable.Columns[0].Caption = "detail1";
            myDataTable.Columns[1].Caption = "detail2";
            myDataTable.Columns[2].Caption = "detail3";
        }
        finally
        {
            conn.Close();
        }
 
        return myDataTable;
    }
protected void RadGrid1_ItemCommand(object sender, GridCommandEventArgs e)
 {
   if (e.CommandName == "RowClick")
    {
      setHeading();
    }
   if (e.CommandName == RadGrid.ExpandCollapseCommandName)
    {
       setHeading();
            
    }
 }
public void setHeading()
 {
   foreach (GridDataItem item in RadGrid1.MasterTableView.Items)
    {
       GridTableView second_tableView = (GridTableView)item.ChildItem.NestedTableViews[0];
       GridHeaderItem it = second_tableView.GetItems(GridItemType.Header)[0] as GridHeaderItem;
       int i = 0;
       foreach (GridColumn col in second_tableView.Columns)
        {
             it[col.UniqueName].Text = myDataTable.Columns[i].Caption;
             i++;
        }
    }
 }

Thanks,
Shinu.
Tags
Grid
Asked by
Jean-Marc
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Jean-Marc
Top achievements
Rank 1
Princy
Top achievements
Rank 2
Share this question
or