ASP.net C# Name gridview columns after custom DataBind
Is there the possibility to give a gridview's columns a custom name using programming code (C#) ?
F.E. I databind my gridview (which is empty in my aspx, except for the layout) using following code :
SqlCommand objCommand = new SqlCommand("SELECT M.Mod_ID, M.Mod_Naam, M.Mod_Omschrijving, M.Taal_Id, M.User_ID FROM Toewijzing T, Model M WHERE T.User_ID = '" + Session["userid"].ToString() + "' AND T.Toe_Status = '" + "ja" + "' AND M.Mod_ID = T.Mod_ID", con);
dr = objCommand.ExecuteReader();
gvIngevuld.DataSource = dr;
gvIngevuld.开发者_运维百科DataBind();
dr.Close();
How do I give these columns a custom name? Like F.E. "Modelnr." for the first column, "Modelnaam" for the 2nd, etc.
Also I was wondering if there was an option to enable paging (per 20 records) and to enable sorting ?
Any help is welcome !
Thank you.
You can do this in your SQL
query can like
SELECT M.Mod_Naam as [Modelnaam] FROM Toewijzing T, Model M
SQL Alias Syntax for Columns
SELECT column_name AS alias_name
FROM table_name
By C#
GridView1.Columns[0].HeaderText = "Header";
GridView1.DataBind();
精彩评论