Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8015073
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T20:08:42+00:00 2026-06-04T20:08:42+00:00

I have a GrdiView on an asp.net page. I am setting the datasource to

  • 0

I have a GrdiView on an asp.net page. I am setting the datasource to a DataTable. I need to set HorizontalAlign to left if the value in the cell is of type string, else if it is a decimal, I want it to be aligned to the right. Please let me know how to implement this. The code for the GridView is as follows:

      <asp:GridView ID="gridViewReport" runat="server" Height="1px"       OnRowDataBound="UsersGVRowDataBound" GridLines="both" Style="z-index: 100; 
        left: 2px; position: absolute; top: 1px; " Width="939px" CellPadding="4"   ForeColor="#333333" AllowSorting="True" OnSorting="gridViewReport_Sorting" Font-Names="Verdana" Font-Size="12px" OnSelectedIndexChanged="gridViewReport_SelectedIndexChanged1">
        <AlternatingRowStyle BackColor="White" />
        <RowStyle HorizontalAlign="Left" BackColor="#EFECE5" />            
        <FooterStyle BackColor="#1C5E55" Font-Bold="True" ForeColor="White" />
        <PagerStyle BackColor="#666666" ForeColor="White" HorizontalAlign="Center" />
        <SelectedRowStyle BackColor="#C0F6C0" ForeColor="#333333" Font-Bold="True" />
        <HeaderStyle BackColor="#CDE472"  Font-Bold="True" ForeColor="DarkGreen" HorizontalAlign ="Left"  Font-Italic="False" Font-Names="Verdana" Font-Overline="False"/>
        <EditRowStyle BackColor="#EAEAAE" />            
    </asp:GridView> 

Also, the code for setting the DataSource is as follows:

gridViewReport.DataSource = _reportTable;
gridViewReport.DataBind();
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T20:08:45+00:00Added an answer on June 4, 2026 at 8:08 pm

    if each of your columns contain data of the same type you would already know which columns carry decimal and which don’t

    so considering your DataTable has two columns and first column is carrying string and second column is carrying decimal you can do

        protected void gridViewReport_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                e.Row.Cells[0].HorizontalAlign = HorizontalAlign.Left;
                e.Row.Cells[1].HorizontalAlign = HorizontalAlign.Right;       
            }
        }
    

    else if your column carries text which can either be a decimal or string you can do this (say the second column in DataTable has text which can potentially contain decimal format as well)

        protected void gridViewReport_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                decimal val;
                if(decimal.TryParse(e.Row.Cells[1].Text, out val))
                    e.Row.Cells[1].HorizontalAlign = HorizontalAlign.Right;
                else
                    e.Row.Cells[1].HorizontalAlign = HorizontalAlign.Left;
            }
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a gridview in asp.net web page. The datasource comes sql server table.
I have a GridView control on my ASP.NET page that binds to result set
I have an Asp.Net page containing one GridView and a couple of images (google
I have an ASP.NET page where I am showing products in a Gridview control.
I have an ASP.NET 3.5 page with a gridview databound to a generic list
I have an ASP.NET GridView with paging enabled. The list of page indexes are
I have an asp.net page with c# code-behind. I have an event that is
I have a button on my ASP.NET page, which fetches some data from my
I have a ASP.Net web page with a grid view. I want to filter
So I have an ASP.NET page with two controls: a GridView which displays rows

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.