[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());
}
}
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
Re: [RESOLVED] Central Align the Text
Re: [RESOLVED] Central Align the Text
Hey,
Not a problem at all, happy to help!!
Gary