Get the App
SLTechnology News&Howtos  ›  Development  › 

How does asp.net implement the Gridview paging save option

Shulou Source: shulou.com Published: 2022-06-03 07:18:40 11月15日 Update

Editor to share with you how asp.net to achieve Gridview paging save options, I believe that most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to know it!

The code is as follows:

# region / / 'Revision: 1.00 Created Date: 2013-08-02 Created ID: Una [# 1300071] add multiple option boxes

/ / /

/ / Session "take many" box value

/ / /

Private void RememberOldValues ()

{

ArrayList categoryIDList = new ArrayList ()

String index = ""

Foreach (GridViewRow row in gridView.Rows)

{

Index = (string) gridView.DataKeys [row.RowIndex] .value

Bool result = ((CheckBox) row.FindControl ("DeleteThis")) .Checked

/ / Check in the Session

If (Session ["id"]! = null)

CategoryIDList = (ArrayList) Session ["id"]

If (result)

{

If (! categoryIDList.Contains (index))

CategoryIDList.Add (index)

}

Else

CategoryIDList.Remove (index)

}

If (categoryIDList! = null & & categoryIDList.Count > 0)

Session ["id"] = categoryIDList

}

/ / /

/ / before Session, the multi-frame is true.

/ / /

Private void RePopulateValues ()

{

ArrayList categoryIDList = (ArrayList) Session ["id"]

If (categoryIDList! = null & & categoryIDList.Count > 0)

{

Foreach (GridViewRow row in gridView.Rows)

{

String index = (string) gridView.DataKeys [row.RowIndex] .value

If (categoryIDList.Contains (index))

{

CheckBox myCheckBox = (CheckBox) row.FindControl ("DeleteThis")

MyCheckBox.Checked = true

}

}

}

}

# endregion

The copy code is as follows:

Protected void gridView_PageIndexChanging (object sender, GridViewPageEventArgs e)

{

RememberOldValues ()

GridView.PageIndex = e.NewPageIndex

BindData ()

RePopulateValues ()

}

The copy code is as follows:

Protected void btnSelect_Click (object sender, EventArgs e)

{

String items = ""

ArrayList categoryIDList = new ArrayList ()

String index = ""

Foreach (GridViewRow row in gridView.Rows)

{

Index = (string) gridView.DataKeys [row.RowIndex] .value

Bool result = ((CheckBox) row.FindControl ("DeleteThis")) .Checked

/ / Check in the Session

If (Session ["id"]! = null)

CategoryIDList = (ArrayList) Session ["id"]

If (result)

{

If (! categoryIDList.Contains (index))

CategoryIDList.Add (index)

}

Else

CategoryIDList.Remove (index)

}

If (categoryIDList! = null & & categoryIDList.Count > 0)

For (int I = 0; I < categoryIDList.Count; iTunes +)

{

Items + = categoryIDList [I] + ","

}

Items = items.Substring (0, items.Length-1)

ScriptManager.RegisterStartupScript (this, this.GetType (), "," check ('"+ items +"'); ", true)

Session.Remove ("id")

}

The above is all the contents of the article "how to achieve Gridview pagination saving options for asp.net". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Tags: Code articles content not much most more knowledge industry information information channels channels plus reference learning help Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Microsoft Docker NVidia Shulou Information vpn