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

How to Right Indent Item Text?

3 Answers 334 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Robert
Top achievements
Rank 1
Robert asked on 12 Mar 2013, 11:46 PM
I'm switching a web page over from using the GridView control to using the RadGrid control.  One thing I'm stuck on is how to right-indent text in an item.

As you'll see in the first screenshot, the illustrated column is correctly indented.  I did this very simply with this CSS Class:

.indentRight {padding-right:20px}

However, that no longer seems to have any effect in the RadGrid.  I tried changing several things but to no avail.  Here's the markup code in question:

              <telerik:GridBoundColumn DataField="TaskStdHours" HeaderText="Std Hours" ReadOnly="true" SortExpression="TaskStdHours" DataFormatString="{0:F2}"><br>                <HeaderStyle Width="70px" HorizontalAlign="Center" /><br>                <ItemStyle HorizontalAlign="Right" CssClass="indentRight" /><br>              </telerik:GridBoundColumn><br>

What do I need to do to make it look the same as in the GridView?

Robert W.

3 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 13 Mar 2013, 04:02 AM
Hi,

Try the following code.
C#:
void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
{
        if (e.Item is GridDataItem)
        {
            GridDataItem item = (GridDataItem)e.Item;
            item["UniqueName"].Style.Add("text-align", "right");
        }
}

Thanks,
Shinu
0
Robert
Top achievements
Rank 1
answered on 13 Mar 2013, 04:42 AM
Shinu,

I have no problem right-aligning the text.  The problem, as my screenshots show, is that it is too far to the right.  Yet the padding-right has no effect.

That's what I need to fix.

Robert
0
Kostadin
Telerik team
answered on 15 Mar 2013, 01:36 PM
Hi Robert,

As far as I could see the items alignment is central in the GridView. You could use the Shinu's approach to add a padding of the cell. Note that you have to set a column width and set TableLayout property to Fixed Check out the following code snippet.
ASPX:
<MasterTableView TableLayout="Fixed">
                <Columns>
                    <telerik:GridBoundColumn DataField="Column1" HeaderText="Column1" HeaderStyle-Width="100px"></telerik:GridBoundColumn>
C#:
void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
{
        if (e.Item is GridDataItem)
        {
            GridDataItem item = (GridDataItem)e.Item;
            item["UniqueName"].Style.Add("padding-left", "20px");
        }
}

Thank you for contacting us.

Greetings,
Kostadin
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
Tags
Grid
Asked by
Robert
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Robert
Top achievements
Rank 1
Kostadin
Telerik team
Share this question
or