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()); } }




Reply With Quote