Limit rows in Gridview Bind


I am binding a Gridview to SQL like to:


<asp:GridView ID="GridView1" runat="server">


        string strSQLconnection = "Data;Initial Catalog=SQL2008_673062_kids;User ID=**********;Password=***********;";

        SqlConnection sqlConnection = new SqlConnection(strSQLconnection);
        SqlCommand sqlCommand = new SqlCommand("SELECT * FROM tbl_apprenticeship_applications", sqlConnection);

        SqlDataReader reader = sqlCommand.ExecuteReader();

        GridView1.DataSource = reader;

Problem is that ALL the rows are returned, i want to limit the rows, to only show a certain number of rows? is there a way i can do this?


Never mind i worked it out:

    protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e)
        e.Row.Cells[0].Visible = false;


Another question about this, how can i change the column name? one of my columns is called date_added, and i want it to say “Date”, can i do this?


That looks like it limits a column, not a row.

Are you not using Visual Studio??

well if you’re autogenerating columns in your gridview, then you could always do it in your query, like “SELECT date_added as Date” etc.

You can also set a limit on your query as well to say how many rows to bring back.

SELECT TOP 10 FROM tbl_name 

hope this helps