Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How does asp.net implement the Gridview paging save option

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

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!

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.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report