Hey,
I am binding a Gridview to SQL like to:
.aspx
<asp:GridView ID="GridView1" runat="server">
</asp:GridView>
.aspx.cs
string strSQLconnection = "Data Source=tcp:esql2k801.discountasp.net;Initial Catalog=SQL2008_673062_kids;User ID=**********;Password=***********;";
SqlConnection sqlConnection = new SqlConnection(strSQLconnection);
SqlCommand sqlCommand = new SqlCommand("SELECT * FROM tbl_apprenticeship_applications", sqlConnection);
sqlConnection.Open();
SqlDataReader reader = sqlCommand.ExecuteReader();
GridView1.DataSource = reader;
GridView1.DataBind();
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?
Thanks
Never mind i worked it out:
protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e)
{
e.Row.Cells[0].Visible = false;
}
Hey,
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?
Thanks
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