Morpheusweb.it - Risorse per webmaster: script, ASP.NET, C#, Visual Basic .Net, tutorial, asp, javascript, css, php, html, java, ADO, VBScript, forms, frames, Active Server Pages, Dynamic HTML, database, gratis per webmaster e webdesigner

Datagrid Sort - << VB.NET VERSION >>


Sort Datagrid rows (ascending or descending)


<%@ Import Namespace="System.Data.OleDb" %>
<%@ Import Namespace="System.Data" %>
<HTML>
<script language="C#" runat="server">
OleDbConnection myConnection;
protected void Page_Load(Object sender, EventArgs e)
{
  myConnection = new OleDbConnection("Provider=Microsoft.Jet.OleDb.4.0; Data Source=" + Server.MapPath("database/utenti.mdb"));
  if (!IsPostBack)
    BindGrid("id");
}
protected void MyDataGrid_Sort(Object sender, DataGridSortCommandEventArgs e)
{
  BindGrid(e.SortExpression);
}
public void BindGrid(String sortfield)
{
  OleDbDataAdapter myCommand = new OleDbDataAdapter("select * from utenti", myConnection);
  DataSet ds = new DataSet();
  myCommand.Fill(ds, "utenti");
  DataView Source = ds.Tables["utenti"].DefaultView;
  Source.Sort = sortfield;
  MyDataGrid.DataSource=Source;
  MyDataGrid.DataBind();
}
</script>
<body>
<form runat="server" ID="Form1">
<ASP:DataGrid id="MyDataGrid" runat="server" OnSortCommand="MyDataGrid_Sort" Width="700px" BackColor="White"
BorderColor="#CC9966" CellPadding="4" Font-Name="Verdana" Font-Size="8pt" HeaderStyle-BackColor="#aaaadd"
AllowSorting="True" BorderStyle="None" BorderWidth="1px" Font-Names="Verdana">
<FooterStyle ForeColor="#330099" BackColor="#FFFFCC"></FooterStyle>
<SelectedItemStyle Font-Bold="True" ForeColor="#663399" BackColor="#FFCC66"></SelectedItemStyle>
<ItemStyle ForeColor="#330099" BackColor="White"></ItemStyle>
<HeaderStyle Font-Bold="True" ForeColor="#FFFFCC" BackColor="#990000"></HeaderStyle>
<PagerStyle HorizontalAlign="Center" ForeColor="#330099" BackColor="#FFFFCC"></PagerStyle>
</ASP:DataGrid>
</form>
</body>
</HTML>



Download Code...


Print Page


 








Page top

risorse per webmaster