Results 1 to 4 of 4

Thread: [RESOLVED] Central Align the Text

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Oct 2009
    Posts
    105

    Resolved [RESOLVED] Central Align the Text

    I m binding the GridView with DB. I want that columns text should be center align. I m able to bind the GridView with DB correctly. I just wnat a code for center align the text.

    Code:
     <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False">
                            <Columns>
                                <asp:BoundField DataField="ProdId" HeaderText="Prod ID" >
                                    <ItemStyle Width="80px"  />
                                </asp:BoundField>
                                <asp:BoundField DataField="ProdName"   HeaderText="Prod Name" >
                                <ItemStyle Width="100px" />
                                </asp:BoundField>
                                <asp:BoundField  DataField="ProdDesc" HeaderText="Prod desc" />
                            </Columns>
                        </asp:GridView>

    Code:
    public partial class Frmgridview : System.Web.UI.Page
    {
        SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString); 
    
    
        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                SqlCommand cmd = new SqlCommand("SELECT * FROM Products", conn);
                conn.Open();
                GridView1.DataSource = cmd.ExecuteReader();
                GridView1.DataBind();
            }
            catch (Exception ex)
            {
                Response.Write(ex.Message.ToString()); 
            }
    
            
           
        }

  2. #2
    PowerPoster gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    Re: Central Align the Text

    Hey,

    Have you tried the HorizontalAlign property of the ItemStyle of the BoundField?

    Code:
    <ItemStyle HorizontalAlign="Center">
    You can find more information here:

    http://www.java2s.com/Code/ASP/XML/a...nalignment.htm

    Hope that helps!!

    Gary

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Oct 2009
    Posts
    105

    Re: [RESOLVED] Central Align the Text

    Thx gep.

  4. #4
    PowerPoster gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    Re: [RESOLVED] Central Align the Text

    Hey,

    Not a problem at all, happy to help!!

    Gary

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width