0

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.

1 Answer 1

2

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();
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you very much ! Any idea how to enable sorting and paging ?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.