In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article mainly explains "what is the use of gridview controls in asp.net". Interested friends may wish to have a look at it. The method introduced in this paper is simple, fast and practical. Next, let the editor take you to learn "what are the ways to use gridview controls in asp.net?"
1.GridView has no code for paging sorting:
Effect picture:
Tips:
1.AllowSorting is set to AllowSorting= "True" in the True,aspx code
two。 The default is 10 per page. If you want to modify the number of entries per page, you can modify PageSize, which is PageSize= "12" in aspx code.
3. The default is one-way sorting, right-click GridView pop-up "Properties", select AllowSorting as True.
2.GridView select, edit, cancel, delete:
Effect picture:
Background code:
You can use sqlhelper. This article is useless. The code is as follows:
Using System;using System.Data;using System.Configuration;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 _ Default: System.Web.UI.Page {SqlConnection sqlcon;SqlCommand sqlcom;string strCon = "Data Source= (local); Database= database name; Uid= account; Pwd= password" Protected void Page_Load (object sender, EventArgs e) {if (! IsPostBack) {bind ();}} protected void GridView1_RowEditing (object sender, GridViewEditEventArgs e) {GridView1.EditIndex = e.NewEditIndex ();} / delete protected void GridView1_RowDeleting (object sender, GridViewDeleteEventArgs e) {string sqlstr = "delete from Table where id='" + GridView1.DataKeys [e.RowIndex] .Value.ToString () + "'; sqlcon = new SqlConnection (strCon); sqlcom = new SqlCommand (sqlstr,sqlcon); sqlcon.Open (); sqlcom.ExecuteNonQuery () Sqlcon.Close (); bind ();} / / Update protected void GridView1_RowUpdating (object sender, GridViewUpdateEventArgs e) {sqlcon = new SqlConnection (strCon) String sqlstr = "update table set field 1 runs'" + ((TextBox) (GridView1.Rows [e.RowIndex] .cells [1] .controls [0])) .Text.ToString () .GridView1.Rows [e.RowIndex] .cells (). Text.ToString (). Trim () + "') Field 3fields'"+ ((TextBox) (GridView1.Rows [e.RowIndex] .cells [3] .controls [0])) .Trim () +" 'where id=' "+ GridView1.DataKeys [e.RowIndex] .Value.ToString () +"' " Sqlcom=new SqlCommand (sqlstr,sqlcon); sqlcon.Open (); sqlcom.ExecuteNonQuery (); sqlcon.Close (); GridView1.EditIndex =-1 GridView1.EditIndex bind ();} / cancel protected void GridView1_RowCancelingEdit (object sender, GridViewCancelEditEventArgs e) {GridView1.EditIndex =-1 GridView1.EditIndex ();} / bind public void bind () {string sqlstr = "select * bind Table"; sqlcon = new SqlConnection (strCon); SqlDataAdapter myda = new SqlDataAdapter (sqlstr,sqlcon); DataSet myds = new DataSet (); sqlcon.Open (); myda.Fill (myds, "Table") GridView1.DataSource = myds;GridView1.DataKeyNames = new string [] {"id"}; / / Primary key GridView1.DataBind (); sqlcon.Close ();}}
The main code of the front desk:
......
3.GridView positive and negative bi-directional sorting:
Effect picture: click the name twice to sort, click the other is also possible.
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 {SqlConnection sqlcon;string strCon = "Data Source= (local); Database= North Wind Trade; Uid=sa;Pwd=" Protected void Page_Load (object sender, EventArgs e) {if (! IsPostBack) {ViewState ["SortOrder"] = "ID card number"; ViewState ["OrderDire"] = "ASC"; bind ();}} protected void GridView1_Sorting (object sender, GridViewSortEventArgs e) {string sPage = e.SortExpressionif (ViewState ["SortOrder"]. ToString () = sPage) {if (ViewState ["OrderDire"]. ToString () = "Desc") ViewState ["OrderDire"] = "ASC"; elseViewState ["OrderDire"] = "Desc" } else {ViewState ["SortOrder"] = e.SortOrder expression;} 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 ();}}
The main code of the front desk:
The combination of 4.GridView and drop-down menu DropDownList:
Effect picture:
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 Default4: System.Web.UI.Page {SqlConnection sqlcon;string strCon = "Data Source= (local); Database= North Wind Trade; Uid=sa;Pwd=sa"; protected void Page_Load (object sender, EventArgs e) {DropDownList ddl If (! IsPostBack) {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"); GridView1.DataSource = myds;GridView1.DataBind (); for (int I = 0; I
5.GridView and CheckBox combine:
Effect picture:
Background code:
Using System;using System.Data;using System.Configuration;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 Default5: System.Web.UI.Page {SqlConnection sqlcon;string strCon = "Data Source= (local); Database= North Wind Trade; Uid=sa;Pwd=sa"; protected void Page_Load (object sender, EventArgs e) {if (! IsPostBack) {bind () }} protected void CheckBox2_CheckedChanged (object sender, EventArgs e) {for (int I = 0; I)
Foreground code:
Appendix-commonly used formatting formulas:
{0purc} currency
{0:D4} displays integers in a 4-character-wide field filled with 0
{0VR 000.0} rounding decimal point to retain the number of significant digits
{0:N2} decimal point retains 2 significant digits; {0:N2}% decimal point retains 2 significant digits plus percent sign
{0 0:yy-MM-dd D} long date; {0 d} short date; {date} e.g. 07-3-25; {0:yyyy-MM-dd} for example, 2007-3-25
Here are three wonderful topics for you:
ASP.NET Control user Manual
ASP.NET data-bound controls use summaries
ASP.NET control uses summarization
At this point, I believe you have a deeper understanding of "what is the use of gridview controls in asp.net?" you might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.