IList怎么和DataGrid绑定
来源:互联网 发布:linux查看进程占用cpu 编辑:程序博客网 时间:2024/04/29 13:57
<form runat="server">
<asp:DataGrid id="DataGrid1" runat="server" />
<BR>
<asp:DataGrid id="DataGrid2" runat="server" AutoGenerateColumns="false">
<Columns>
<asp:TemplateColumn HeaderText="value">
<ItemTemplate>
<%# DataBinder.Eval(Container.DataItem,"MyProp") %>
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:DataGrid>
<asp:Button id="btn" runat="server" Text="Refresh" />
</form>
<script language="C#" runat="server">
class MyClass
{
string ms;
public MyClass(string s)
{
ms =s;
}
public string MyProp
{
get {return ms;}
}
}
void Page_Load(Object sender, EventArgs e)
{
if (!IsPostBack)
{
ArrayList al = new ArrayList();
al.Add(new MyClass("a"));
al.Add(new MyClass("b"));
DataGrid1.DataSource = (IList)al;
DataGrid1.DataBind();
DataGrid2.DataSource = (IList)al;
DataGrid2.DataBind();
}
}
</script>
资料2 :
来源: http://www.codes-bbs.cn/html/ASP-NET/2006/10/43486.html
我把代码整理一下:
public class RowData
{
public string product_id;
public string product_nm;
public string Product_id
{
get{return product_id;}
set{product_id = value;}
}
public string Product_nm
{
get{return product_nm;}
set{product_nm = value;}
}
public RowData(string id,string des)
{
this.Product_id=id;
this.Product_nm=des;
}
}
class RowDataCollection:CollectionBase
{
public RowData this[ int index ]
{
get
{
return( (RowData) List[index] );
}
set
{
List[index] = value;
}
}
public int Add( RowData value )
{
return( List.Add( value ) );
}
public int IndexOf( RowData value )
{
return( List.IndexOf( value ) );
}
public void Insert( int index, RowData value )
{
List.Insert( index, value );
}
public void Remove( RowData value )
{
List.Remove( value );
}
public bool Contains( RowData value )
{
// If value is not of type RowData, this will return false.
return( List.Contains( value ) );
}
protected override void OnInsert( int index, Object value )
{
if ( value.GetType() != Type.GetType("WebApplication1.RowData") )
throw new ArgumentException( "value must be of type RowData.", "value" );
}
protected override void OnRemove( int index, Object value )
{
if ( value.GetType() != Type.GetType("WebApplication1.RowData") )
throw new ArgumentException( "value must be of type RowData.", "value" );
}
protected override void OnSet( int index, Object oldValue, Object newValue )
{
if ( newValue.GetType() != Type.GetType("WebApplication1.RowData") )
throw new ArgumentException( "newValue must be of type RowData.", "newValue" );
}
protected override void OnValidate( Object value )
{
if ( value.GetType() != Type.GetType("WebApplication1.RowData") )
throw new ArgumentException( "value must be of type RowData." );
}
}
class Test
{
private RowDataCollection m_RowDataCollection;
public RowDataCollection RowCollection
{
set{m_RowDataCollection=value;}
get{return m_RowDataCollection;}
}
public void LoadData()
{
this.RowCollection=new RowDataCollection();
this.RowCollection.Add(new RowData("7201","aaaaaa"));
this.RowCollection.Add(new RowData("7202","aaaaaa"));
this.RowCollection.Add(new RowData("7203","aaaaaa"));
this.RowCollection.Add(new RowData("7204","aaaaaa"));
}
}
private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
Test t=new Test();
t.LoadData();
RowData rd=t.RowCollection[1];
this.DataGrid1.DataSource=t.RowCollection;
this.DataGrid1.DataBind();
}
<asp:DataGrid id="DataGrid1" runat="server" Width="529px" Height="208px" AutoGenerateColumns="False">
<Columns>
<asp:BoundColumn HeaderText="a1" DataField="product_id"></asp:BoundColumn>
<asp:BoundColumn HeaderText="a2" DataField="product_nm"></asp:BoundColumn>
</Columns>
</asp:DataGrid>
- IList怎么和DataGrid绑定
- Repeater绑定datarow和ilist
- 如何绑定IList集合中对象的复合属性到DataGrid中。
- DataGrid和DataGridComboBoxColumn数据绑定
- GridView绑定IList数组内容
- ComboBox绑定IList 或 ArrayList
- Repeater绑定IList<T>数据源
- 怎么在绑定后动态改变DataGrid中的内容
- 怎么在绑定后动态改变DataGrid中的内容
- 怎么在绑定后动态改变DataGrid中的内容
- 如何绑定DATAGRID控件和XML文档
- IList和List区别
- IList 和List 区别
- IList 和List 区别
- IList和List解惑
- 泛型List和IList
- IList
- IList
- google优化
- How to Become a Hacker
- 没有感觉 ,From dereism to self-confidence and friend's
- 文件操作
- 2007年第24周CSDN读书排行榜:《SQL必知必会》继续称王
- IList怎么和DataGrid绑定
- 周鸿祎踢前锋,互联网草根队集体亮相
- 越南文续--码表
- 大家都很郁闷
- 初连ORACLE
- 英语天天秀(2007/06/18 ) -- 50部百年电影经典名句
- [转]Amit's Astar Page中译文
- 互联网协会公布“恶意软件定义”细则
- 生活美文 --魚和水的故事