Effect Picture: Point Name each 2 times of the order, point other also can.
Background code:
Using System;
Using System.Data;
Using System.Configuration;
Using System.Collections;
Using System.Web;
Using System.Web.Security;
Using System.Web.UI;
Using System.Web.UI.WebControls;
Using System.Web.UI.WebControls.WebParts;
Using System.Web.UI.HtmlControls;
Using System.Data.SqlClient;
public partial class Default3:System.Web.UI.Page
{
Qingqing Moon's Blog http://blog.csdn.net/21aspnet
SqlConnection Sqlcon;
String Strcon = "Data source= (local);D atabase= North Wind trade; Uid=sa; Pwd= ";
protected void Page_Load (object sender, EventArgs e)
{
if (! IsPostBack)
{
viewstate["SortOrder"] = "identity card number";
viewstate["Orderdire"] = "ASC";
Bind ();
}
}
protected void Gridview1_sorting (object sender, GridViewSortEventArgs e)
{
string spage = E.sortexpression;
if (viewstate["SortOrder"]. ToString () = = spage)
{
if (viewstate["Orderdire"]. ToString () = = "Desc")
viewstate["Orderdire"] = "ASC";
Else
viewstate["Orderdire"] = "Desc";
}
Else
{
viewstate["SortOrder"] = e.sortexpression;
}
Bind ();
}
public void bind ()
{
String sqlstr = "SELECT Top 5 * from flying Fox Studio";
Sqlcon = new SqlConnection (Strcon);
SqlDataAdapter Myda = new SqlDataAdapter (Sqlstr, Sqlcon);
DataSet myds = new DataSet ();
Sqlcon. Open ();
Myda. Fill (myDS, "Flying Fox Studio");
DataView view = myDS. Tables["Flying Fox Studio"]. DefaultView;
String sort = (string) viewstate["SortOrder"] + "" + (String) viewstate["Orderdire"];
View. sort = sort;
Gridview1.datasource = view;
Gridview1.databind ();
Sqlcon. Close ();
}
}
前台主要代码:
<asp:gridview id= "GridView1" runat= "Server" allowsorting= "True" autogeneratecolumns= "False"
cellpadding= "3" font-size= "9pt" onsorting= "gridview1_sorting" back Color= "White" bordercolor= "#CCCCCC" borderstyle= "None" borderwidth= "1px"
<footerstyle B Ackcolor= "White" forecolor= "#000066"/>
<columns>
&L T;asp:boundfield datafield= "ID number" headertext= "User ID" sortexpression= "identity card number"/>
<asp: BoundField datafield= "name headertext=" user name
" SortExpression="姓名"/>
<asp:BoundField DataField="员工性别" HeaderText="性别" SortExpression="员工性别"/>
<asp:BoundField DataField="家庭住址" HeaderText="家庭住址" SortExpression="家庭住址"/>
</Columns>
<RowStyle ForeColor="#000066" />
<SelectedRowStyle BackColor="#669999" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="White" ForeColor="#000066" HorizontalAlign="Left" />
<HeaderStyle BackColor="#006699" Font-Bold="True" ForeColor="White" />
</asp:GridView>
Author of this article: unknown