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

Excel Like Grid

5 Answers 53 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Dennis
Top achievements
Rank 1
Dennis asked on 03 Mar 2011, 11:37 AM
Hi,

I want a Grid to behave somewhat like Excel where if the cell has numeric data, it should appear on the right of the cell and if contains a non-numeric data, it should appear on the left of the cell. Please let me know how to achieve this with the RadGrid Control.

Thanks.

5 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 1
answered on 03 Mar 2011, 12:09 PM
Hello David,

You can set alighment of cell depending on column. Sample code is given below.

C#:
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
    {
       if (e.Item is GridDataItem)
        {
            GridDataItem item = (GridDataItem)e.Item;
            TableCell cell1 = (TableCell)item["total"];//numeric data
            cell1.Style["text-align"] = "right";
            TableCell cell2 = (TableCell)item["Name"];
            cell2.Style["text-align"] = "left";
        }
   }

Thanks,
Princy.
0
Dennis
Top achievements
Rank 1
answered on 06 Mar 2011, 09:23 AM
Hi Princy,

Thanks for the Reply. Well my Grid has AutoGeneratedColumns and the DataSource for the Grid is not static at all. So i want it in a way that a Grid to automatically detect from the Database that if the column is numeric then the alignment of the data in the cell to be in right and if non-numeric then alignment to be on left. Please let me know how would this be possible.

Thanks.
0
Shinu
Top achievements
Rank 1
answered on 07 Mar 2011, 10:06 AM
Hello David,

If you want to align AutoGeneratedColumns based on its data type, try the following code snippet.

C#:
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
   {
       if (e.Item is GridDataItem)
       {
           GridDataItem item = (GridDataItem)e.Item;
           foreach (GridColumn col in RadGrid1.MasterTableView.AutoGeneratedColumns)
           {
               TableCell cell = (TableCell)item[col.UniqueName];
               if (col.DataType.FullName == "System.String")
                   cell.Style["text-align"] = "left";
               else
                   cell.Style["text-align"] = "right";
           }
        }
   }

-Shinu.
0
Joel
Top achievements
Rank 1
answered on 29 Aug 2014, 05:42 PM
Hello, I've implemented the Excel look and feel for RadGrid (i got it from here http://www.telerik.com/support/code-library/excel-look-and-feel-for-radgrid).

The thing is our customer has asked us to add a template column containing a RadComboBox with checkboxes enabled.

My problem is I cannot find the way to to access this radcombobox after a row is inserted, therefore the grid is reseting all the selected checkboxes when the postback happens. 

Is it possible to do this or this "type" of grid is Restricted to GridBoundColumn, GridDropDownColumn, GridNumericColumn, GridMaskedColumn, and GridDateTimeColumn column types.??

When I try to loop thru the column controls I get the error Object reference not set to an instance of an object.

private object GetColumnValue(GridColumn column, GridDataItem item)
    {
        Hashtable table = new Hashtable();
        item.ExtractValues(table);
 
        switch (column.ColumnType)
        {
            case "GridTemplateColumn":
                //if (column.UniqueName == "CategoryIDs")
                {
                    foreach (Control c in item[column.UniqueName].Controls)
                    {
                        UB.MSSql.WebLog(c.ID);
                    }
                }
                return null;
            default:
                 
                return table[column.UniqueName];
        }
         
    }



Any help would be appreciated.

Thanks

0
Joel
Top achievements
Rank 1
answered on 29 Aug 2014, 06:06 PM
Nevermind found the way to do it.


Thanks
Tags
Grid
Asked by
Dennis
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 1
Dennis
Top achievements
Rank 1
Shinu
Top achievements
Rank 1
Joel
Top achievements
Rank 1
Share this question
or