Assume that your results from database is put on list, and each row of results is put on Student class.
IList<student> listStudent</student>
Assume that Student class is below:
public class Student {
public string StudentID {set; get;}
public string StudentName {set; get;}
}
In aspx file, put tag gridview, see the below for example:
<asp:gridview runat="server" id="gvStudent" autogeneratecolumns="False" xmlns:asp="#unknown">
AllowPaging="True" AllowSorting="False" EmptyDataText="No Data Found"
HorizontalAlign="Center" Width="100%" DataKeyNames="StudentID " PageSize="20">
<emptydatarowstyle horizontalalign="Center" verticalalign="Middle" width="100%" />
<columns>
<asp:templatefield headertext="No.">
<headerstyle width="5%"></headerstyle>
<itemtemplate>
<asp:label id="Label2" runat="server" name="No" text="<%# (gvStudent.PageIndex * gvStudent.PageSize) + gvStudent.Rows.Count + 1 %>">
</asp:label>
</itemtemplate>
<itemstyle horizontalalign="Center" />
</asp:templatefield>
<asp:boundfield headertext="Student ID" datafield="StudentID" />
<asp:boundfield headertext="Student Name" datafield="StudentName" />
</columns>
</asp:gridview>
And in code behind, see the below for the example:
private void BindGridView()
{
IList<student> listStudent = ......
this.gvStudent.DataSource = listStudent;
this.gvStudent.DataBind();
}
</student>
And call method BindGrindView on button click
Or you can see from other tutorial about gridview in codeproject
http://www.codeproject.com/Articles/14249/How-to-populate-DataGridView-GridView-with-SQL-sta[
^]