ASP.net ListItem Attributes 属性回传丢失的解决方案
该方法为网上整理
1. 新继承一个列表控件
新控件中重写两个方法:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI.WebControls; namespace GetDateDome
{
public class ListBoxEx:ListBox
{
protected override object SaveViewState()
{
// create object array for Item count + 1
object[] allStates = new object[this.Items.Count + ]; // the +1 is to hold the base info
object baseState = base.SaveViewState();
allStates[] = baseState; Int32 i = ;
// now loop through and save each Style attribute for the List
foreach (ListItem li in this.Items)
{
Int32 j = ;
string[][] attributes = new string[li.Attributes.Count][];
foreach (string attribute in li.Attributes.Keys)
{
attributes[j++] = new string[] { attribute, li.Attributes[attribute] };
}
allStates[i++] = attributes;
}
return allStates;
} protected override void LoadViewState(object savedState)
{
if (savedState != null)
{
object[] myState = (object[])savedState; // restore base first
if (myState[] != null)
base.LoadViewState(myState[]); Int32 i = ;
foreach (ListItem li in this.Items)
{
// loop through and restore each style attribute
foreach (string[] attribute in (string[][])myState[i++])
{
li.Attributes[attribute[]] = attribute[];
}
}
}
} }
}
2 页面注册控件
<%@ Register assembly="GetDateDome" namespace="GetDateDome" tagprefix="my" %>
3 使用新控件
<my:ListBoxEx ID="lstUnselectCol" runat="server" Style="width: 100%;height:100%;" ></my:ListBoxEx>
//设置属性
ListItem p = new ListItem(i["Item"].ToString(), i["value"].ToString());
p.Attributes.Add("type", i["type"].ToString());
lstUnselectCol.Items.Add(p); //获取属性
string msg = srcList.SelectedItem.Attributes["type"];
4 最后记着设置 EnableViewState="true"
ASP.net ListItem Attributes 属性回传丢失的解决方案的更多相关文章
- ASP.NET状态服务及session丢失问题解决方案总结
原文:ASP.NET状态服务及session丢失问题解决方案总结[转载] asp.net Session的实现: asp.net的Session是基于HttpModule技术做的,HttpModule ...
- ASP.NET 状态服务 及 session丢失问题解决方案总结
ASP.NET2.0系统时,在程序中做删除或创建文件操作时,出现session丢失问题.采用了如下方法:1.asp.net Session的实现:asp.net的Session是基于HttpModul ...
- [转]ASP.NET 状态服务 及 session丢失问题解决方案总结
转自[http://blog.csdn.net/high_mount/archive/2007/05/09/1601854.aspx] 最近在开发一ASP.NET2.0系统时,在程序中做删除或创建文件 ...
- 【翻译】ASP.NET MVC 5属性路由(转)
转载链接:http://www.cnblogs.com/thestartdream/p/4246533.html 原文链接:http://blogs.msdn.com/b/webdev/archive ...
- Asp.net页面跳转Session丢失问题
原本去年在做项目时,写好的一记篇博客分享给大家. Asp.net页面跳转Session丢失问题 编写人:CC阿爸 2014-4-2 l 近来在做泛微OA与公司自行开发的系统集成登录的问题.在使用 ...
- ASP.NET控件属性大全
ASP.NET控件属性大全 DataGridView 控件DataGridView 控件提供用来显示数据的可自定义表.使用 DataGridView 类,可以自定义单元格.行.列和边框. 注意Data ...
- IIS安全工具UrlScan介绍 ASP.NET 两种超强SQL 注入免费解决方案( 基于IIS,使用免费工具) 批改或隐藏IIS7.5的Server头信息 移除X-Powered-By,MVC,ASP.NET_SessionId 的 HTTP头或者cookie名称
微软给了我们一个很好的工具用来使IIS安全的运行-------UrlScan,下面是它的配置文件介绍 [options]UseAllowVerbs=1 ; 若为1,则使用 ...
- asp.net web api2.0 ajax跨域解决方案
asp.net web api2.0 ajax跨域解决方案 Web Api的优缺点就不说了,直接说怎么跨域,我搜了一下,主要是有两种. 一,ASP.NET Web API支持JSONP,分两种 1, ...
- 计算价格, java中浮点数精度丢失的解决方案
计算价格, java中浮点数精度丢失的解决方案
随机推荐
- 针对淡入淡出的定时轮播效果js
如果不使用jquery的fadeIn和fadeOut的接口和不适用animate情况下,如果要做用js实现淡入淡出轮播效果,我所想到的办法就是使用css3新特性transition(注意好兼容性). ...
- 黑马程序员——Java高级应用(一)
------<a href="http://www.itheima.com" target="blank">Java培训.Android培训.iOS ...
- Microsoft Visual Studio 产品密钥
Microsoft Visual Studio 2010 产品密钥:YCFHQ-9DWCY-DKV88-T2TMH-G7BHP Microsoft Visual Studio 2013 产品密钥:BW ...
- 分页搜索查询sql
select * from (select t.*,rownum no from " + table + " t where scbj=0)where (no>(" ...
- linux 虚拟机centos64位_6.5+VM10 主机是固定IP局域网设置代理上网,虚机设置固定ip 图文详细步骤
一种: 虚机是Desktop 安装 1.虚拟机—设置—网络适配器子选项—选择“桥接模式” 2.在虚拟机中选择系统(System)—首选项(Preferences)—网络连接(Network Conne ...
- mac中遇到的mysql编码问题
由于项目有需要支持表情包输入数据库,自己做了一下技术测试,修改了my.cnf的权限为777.结果就操蛋了.编码错误.... 直到我无意地输入mysql -h,提示我/etc/my.cnf被忽略的一段话 ...
- ESP8266固件修改可以控制多个IO方法
之前在论坛上找到了一个通过ESP8266可以控制GPIO0的固件和app,但是自己做的家庭影音灯光系统是需要控制多个IO从而控制STM32.通过观看大明的视频,了解了GPIO的控制方法. 在固件的ap ...
- Win7中,取消共享文件夹后有个小锁
用过windows7的朋友都知道,Windows 7 中设置某一个文件夹属性为共享后,文件夹的图标上就增加一个小锁图案.起到了一个标记作用,挺好的.但是即使你将该文件夹的共享功能取消后,该小锁图案还是 ...
- UVa 232 Crossword Answers
Crossword Answers A crossword puzzle consists of a rectangular grid of black and white squares and ...
- [bzoj 1001][Beijing2006]狼抓兔子 (最小割+对偶图+最短路)
Description 现在小朋友们最喜欢的"喜羊羊与灰太狼",话说灰太狼抓羊不到,但抓兔子还是比较在行的, 而且现在的兔子还比较笨,它们只有两个窝,现在你做为狼王,面对下面这样一 ...