我在一个自定义控件中有一个Collection属性DataKeys,其中DataKey有一项子属性的类型是枚举,但在设计时的状态下,我每次加了一个DataKey,退出后的值却没有反映到控件的代码中,再进行设置的时候,DataKeys中的值又清空了,哪位大哥能帮一下我呢?下面是代码:
DataKey.cs
using System;
using System.Collections;
using System.ComponentModel;
using System.ComponentModel.Design.Serialization;
using System.Globalization;
using System.Reflection;
namespace TTools.TWebControls
{
//[TypeConverter(typeof(DataKey.TDataKeyConverter))]
[ToolboxItem(false)]
[Serializable]
public class DataKey : System.Web.UI.Control
{
string _keyName;
string _keyValue;
DataKeyTypeEnum _keyType = DataKeyTypeEnum.String;
public string KeyName
{
get
{
return (_keyName);
}
set
{
_keyName = value;
}
}
public string KeyValue
{
get
{
return (_keyValue);
}
set
{
_keyValue = value;
}
} public DataKeyTypeEnum KeyType
{
get { return _keyType; }
set { _keyType = value; }
} public DataKey() : this(null, null,DataKeyTypeEnum.String)
{ } public DataKey(string keyName) : this(keyName, null)
{ } public DataKey(string keyName, string keyValue)
: this(keyName, keyValue, DataKeyTypeEnum.String)
{
}
public DataKey(string keyName, string keyValue,DataKeyTypeEnum keyType)
{
this._keyName = keyName;
this.KeyValue = keyValue;
this._keyType = keyType;
}
}
}
DataKeyCollection.csusing System;
using System.Collections;
using System.Globalization;
using System.ComponentModel;
using System.ComponentModel.Design.Serialization;namespace TTools.TWebControls
{
[Serializable]
public class DataKeyCollection : System.Collections.CollectionBase, IEnumerable
{
public DataKeyCollection()
{
//ArrayList();
}
public DataKeyCollection(ArrayList al)
{
for(int i=0;i<al.Count;i++)
{
InnerList.Add((DataKey)al[i]);
}
}
#region Methods
public int Add(object value)
{
Add((DataKey)value);
return Count - 1;
}
public DataKey Add(DataKey _dataKey)
{
InnerList.Add(_dataKey);
return _dataKey;
} public DataKey Add(string keyName)
{
DataKey _dataKey = new DataKey(keyName);
return Add(_dataKey);
} public DataKey Add(string keyName, string keyValue)
{
DataKey _dataKey = new DataKey(keyName, keyValue);
return Add(_dataKey);
} public DataKey Add(string keyName, string keyValue,DataKeyTypeEnum keyType)
{
DataKey _dataKey = new DataKey(keyName, keyValue, keyType);
return Add(_dataKey);
}
public bool Contains(object value)
{
return (-1 != this.IndexOf(value));
}
public bool Contains(string keyName)
{
return (-1 != this.IndexOf(keyName));
} public int IndexOf(DataKey item)
{
return InnerList.IndexOf(item);
}
public int IndexOf(object value)
{
if (value != null)
{
if (this.InnerList != null)
{
int num1 = this.InnerList.Count;
for (int num2 = 0; num2 < num1; num2++)
{
if (value == this.InnerList[num2])
{
return num2;
}
}
}
}
return -1;
}
public int IndexOf(string keyName)
{
if (this.InnerList != null)
{
int num1 = this.InnerList.Count;
for (int num2 = 0; num2 < num1; num2++)
{
if (CultureInfo.CurrentCulture.CompareInfo.Compare(keyName, ((DataKey) this.InnerList[num2]).KeyName, CompareOptions.IgnoreWidth | (CompareOptions.IgnoreKanaType | CompareOptions.IgnoreCase)) == 0)
{
return num2;
}
}
}
return -1;
}
public void Remove(object value)
{
int num1 = this.IndexOf(value);
if (num1 >= 0)
{
this.RemoveAt(num1);
}
}
private void Replace(int index, object newValue)
{
this.InnerList[index] = newValue;
}
#endregion
#region 属性
public DataKey this[int index]
{
get
{
return (DataKey)InnerList[index];
}
set
{
Replace(index, value);
}
}
#endregion
}
}
DataKey.cs
using System;
using System.Collections;
using System.ComponentModel;
using System.ComponentModel.Design.Serialization;
using System.Globalization;
using System.Reflection;
namespace TTools.TWebControls
{
//[TypeConverter(typeof(DataKey.TDataKeyConverter))]
[ToolboxItem(false)]
[Serializable]
public class DataKey : System.Web.UI.Control
{
string _keyName;
string _keyValue;
DataKeyTypeEnum _keyType = DataKeyTypeEnum.String;
public string KeyName
{
get
{
return (_keyName);
}
set
{
_keyName = value;
}
}
public string KeyValue
{
get
{
return (_keyValue);
}
set
{
_keyValue = value;
}
} public DataKeyTypeEnum KeyType
{
get { return _keyType; }
set { _keyType = value; }
} public DataKey() : this(null, null,DataKeyTypeEnum.String)
{ } public DataKey(string keyName) : this(keyName, null)
{ } public DataKey(string keyName, string keyValue)
: this(keyName, keyValue, DataKeyTypeEnum.String)
{
}
public DataKey(string keyName, string keyValue,DataKeyTypeEnum keyType)
{
this._keyName = keyName;
this.KeyValue = keyValue;
this._keyType = keyType;
}
}
}
DataKeyCollection.csusing System;
using System.Collections;
using System.Globalization;
using System.ComponentModel;
using System.ComponentModel.Design.Serialization;namespace TTools.TWebControls
{
[Serializable]
public class DataKeyCollection : System.Collections.CollectionBase, IEnumerable
{
public DataKeyCollection()
{
//ArrayList();
}
public DataKeyCollection(ArrayList al)
{
for(int i=0;i<al.Count;i++)
{
InnerList.Add((DataKey)al[i]);
}
}
#region Methods
public int Add(object value)
{
Add((DataKey)value);
return Count - 1;
}
public DataKey Add(DataKey _dataKey)
{
InnerList.Add(_dataKey);
return _dataKey;
} public DataKey Add(string keyName)
{
DataKey _dataKey = new DataKey(keyName);
return Add(_dataKey);
} public DataKey Add(string keyName, string keyValue)
{
DataKey _dataKey = new DataKey(keyName, keyValue);
return Add(_dataKey);
} public DataKey Add(string keyName, string keyValue,DataKeyTypeEnum keyType)
{
DataKey _dataKey = new DataKey(keyName, keyValue, keyType);
return Add(_dataKey);
}
public bool Contains(object value)
{
return (-1 != this.IndexOf(value));
}
public bool Contains(string keyName)
{
return (-1 != this.IndexOf(keyName));
} public int IndexOf(DataKey item)
{
return InnerList.IndexOf(item);
}
public int IndexOf(object value)
{
if (value != null)
{
if (this.InnerList != null)
{
int num1 = this.InnerList.Count;
for (int num2 = 0; num2 < num1; num2++)
{
if (value == this.InnerList[num2])
{
return num2;
}
}
}
}
return -1;
}
public int IndexOf(string keyName)
{
if (this.InnerList != null)
{
int num1 = this.InnerList.Count;
for (int num2 = 0; num2 < num1; num2++)
{
if (CultureInfo.CurrentCulture.CompareInfo.Compare(keyName, ((DataKey) this.InnerList[num2]).KeyName, CompareOptions.IgnoreWidth | (CompareOptions.IgnoreKanaType | CompareOptions.IgnoreCase)) == 0)
{
return num2;
}
}
}
return -1;
}
public void Remove(object value)
{
int num1 = this.IndexOf(value);
if (num1 >= 0)
{
this.RemoveAt(num1);
}
}
private void Replace(int index, object newValue)
{
this.InnerList[index] = newValue;
}
#endregion
#region 属性
public DataKey this[int index]
{
get
{
return (DataKey)InnerList[index];
}
set
{
Replace(index, value);
}
}
#endregion
}
}
解决方案 »
- 用.net导入EXCEL并将sheet另存为
- LINQ查询,业务层返回一个实体List给aspx页面的东西做datasource
- 我在做ERP角色权限,不知道是用asp.net3.5上的,还是自个写,不知道那上面的灵活吗
- 了解Developer Express控件包的前辈请进
- 如何在Page_Load事件中获取引起回传的控件
- 高手请进!!发送表到服务器端怎么取值~在线等
- 代码表有空格?..........
- 如何在客户端调用后台中的一个方法,在线等。。
- 怎么在vs.net中专门调试.CS文件?我调试老是提示出现错误!!在线等,马上结帐!!!
- session_end这个事件什么时候触发的呀?
- <table cellspacing="1" border="0">如何用css标记表示出来?
- 请问大家一些门户网站的页面里,只要有某个词,就会是链接的模式?怎么做?
考虑用static 或 ViewState或其它的对象存储一下这样的变量