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 to generate checkbox dynamically by asp.net

2025-03-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

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

This article introduces the relevant knowledge of "how asp.net can dynamically generate checkbox". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

Demand:

1 dynamically generate a set of checkbox (data source is DB or memory collection)

When the 2post is submitted, the backend can get it in time.

3 refresh page after submission checkbox remains previously selected or unchecked

4 avoid producing a large amount of viewstate

Solution: use repeater+input (checkbox) + input (hidden)

Html code

The copy code is as follows:

Note: try to write the anonymous function code in OnClick on the top of the page.

Js code

The copy code is as follows:

$(": Hidden [name = 'reportType']") .each (function () {

Var obj = $(this) .prev ()

If (obj.attr ('checked')) {$(this) .val (obj.val ());}

});

Get when the post is submitted by the backend

The copy code is as follows:

String [] _ str = Request ["reportType"] .split (',')

String data will inevitably have empty strings. Be careful to delete them, otherwise there will be a type conversion exception when unpacking.

This is the end of the content of "how to dynamically generate checkbox in asp.net". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

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