该方法为网上整理

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 属性回传丢失的解决方案的更多相关文章

  1. ASP.NET状态服务及session丢失问题解决方案总结

    原文:ASP.NET状态服务及session丢失问题解决方案总结[转载] asp.net Session的实现: asp.net的Session是基于HttpModule技术做的,HttpModule ...

  2. ASP.NET 状态服务 及 session丢失问题解决方案总结

    ASP.NET2.0系统时,在程序中做删除或创建文件操作时,出现session丢失问题.采用了如下方法:1.asp.net Session的实现:asp.net的Session是基于HttpModul ...

  3. [转]ASP.NET 状态服务 及 session丢失问题解决方案总结

    转自[http://blog.csdn.net/high_mount/archive/2007/05/09/1601854.aspx] 最近在开发一ASP.NET2.0系统时,在程序中做删除或创建文件 ...

  4. 【翻译】ASP.NET MVC 5属性路由(转)

    转载链接:http://www.cnblogs.com/thestartdream/p/4246533.html 原文链接:http://blogs.msdn.com/b/webdev/archive ...

  5. Asp.net页面跳转Session丢失问题

    原本去年在做项目时,写好的一记篇博客分享给大家. Asp.net页面跳转Session丢失问题   编写人:CC阿爸 2014-4-2 l  近来在做泛微OA与公司自行开发的系统集成登录的问题.在使用 ...

  6. ASP.NET控件属性大全

    ASP.NET控件属性大全 DataGridView 控件DataGridView 控件提供用来显示数据的可自定义表.使用 DataGridView 类,可以自定义单元格.行.列和边框. 注意Data ...

  7. IIS安全工具UrlScan介绍 ASP.NET 两种超强SQL 注入免费解决方案( 基于IIS,使用免费工具) 批改或隐藏IIS7.5的Server头信息 移除X-Powered-By,MVC,ASP.NET_SessionId 的 HTTP头或者cookie名称

    微软给了我们一个很好的工具用来使IIS安全的运行-------UrlScan,下面是它的配置文件介绍 [options]UseAllowVerbs=1                ; 若为1,则使用 ...

  8. asp.net web api2.0 ajax跨域解决方案

    asp.net web api2.0 ajax跨域解决方案 Web Api的优缺点就不说了,直接说怎么跨域,我搜了一下,主要是有两种.  一,ASP.NET Web API支持JSONP,分两种 1, ...

  9. 计算价格, java中浮点数精度丢失的解决方案

    计算价格, java中浮点数精度丢失的解决方案

随机推荐

  1. 加密解密(2)*客户端,服务器,CA(Certificate Authority),公钥,私钥,证书,签名,验证

    加密解密(2)*客户端,服务器,CA(Certificate Authority),公钥,私钥,证书,签名,验证 各角色比喻 客户端:通常为请求方,要验证服务器的身份. 服务器:通常为响应方,有时也要 ...

  2. [Regular Expressions] Find Plain Text Patterns

    The simplest use of Regular Expressions is to find a plain text pattern. In this lesson we'll look a ...

  3. 文本框按键事件onkeydown、onkeypress、onkeyup区别

    当我们在搜索时,会用到这几个事件 onkeydown 是指鼠标按下的那一刻,此时用户不知道按了什么,文本框也不会显示,首先触发的事件 onkeypress 是指鼠标按下然后松开的瞬间,此时仍然获取不到 ...

  4. this函数的理解

    Javascript的this用法 this是Javascript语言的一个关键字. 它代表函数运行时,自动生成的一个内部对象,只能在函数内部使用.比如, function test(){ this. ...

  5. 解决Android AVD启动报错问题

    好不容易从ADT Bundle转为Android Studio的开发环境,一路荆棘,现在又遇到了模拟器的问题,本来直接用真机调试程序会更快些,但是为了模拟多种系统不得不开启AVD. 废话不说,问题和解 ...

  6. String功能测试

    package foxe; import java.io.IOException;import java.util.StringTokenizer; public class MainClass { ...

  7. 网站飘窗js代码

    <SCRIPT> var imagepath="/${res}/images/geren.jpg" ; var imagewidth=178 ;//这两行写图片的大小 ...

  8. Homebrew -- Mac软件管家(套件管理yun……)

    也许是之前使用linux系统的时候总是习惯使用wget 在mac中只有curl,有点略显不习惯 于是乎某天在搜索mac开发者的时候发现了Homebrew这个东西 ok,是那么句话--惰性是人的天性 有 ...

  9. string 与char* char[]之间的转换

    1.首先必须了解,string可以被看成是以字符为元素的一种容器.字符构成序列(字符串).有时候在字符序列中进行遍历,标准的string类提供了STL容器接口.具有一些成员函数比如begin().en ...

  10. 新花生壳+tomcat(内网映射,无需设置路由器)建站攻略

    说明: 1.适用于内网用户(局域网,校园网,或者公司网等无法更改路由器映射的情况) 2.一共花了8块钱…………心疼.不过如果大家有钱的话,8块钱,少吃一顿麻辣烫就好了~总之,这个适用于测试网站,小访问 ...