像如下的类
private class nums
{
private int _n1,_n2,_n3,_n4;
public int N1
{
get { return _n1;}
set { _n1 = value;}
}public int N2
{
get { return _n2;}
set { _n2 = value;}
}public int N3
{
get { return _n3;}
set { _n3 = value;}
}public int N4
{
get { return _n4;}
set { _n4 = value;}
}
}
我在程序中,用如下代码绑定数据
nums[] MyArray = new nums[3];
...//对MyArray进行操作
dataGrid1.DataSource = MyArray;
本希望在dataGrid中能按照N1,N2,N3,N4的顺序现实数据,但是却是按照N4,N1,N2,N3的顺序显示,不知道有没有什么办法可以解决这个问题。各位仁兄帮个忙
private class nums
{
private int _n1,_n2,_n3,_n4;
public int N1
{
get { return _n1;}
set { _n1 = value;}
}public int N2
{
get { return _n2;}
set { _n2 = value;}
}public int N3
{
get { return _n3;}
set { _n3 = value;}
}public int N4
{
get { return _n4;}
set { _n4 = value;}
}
}
我在程序中,用如下代码绑定数据
nums[] MyArray = new nums[3];
...//对MyArray进行操作
dataGrid1.DataSource = MyArray;
本希望在dataGrid中能按照N1,N2,N3,N4的顺序现实数据,但是却是按照N4,N1,N2,N3的顺序显示,不知道有没有什么办法可以解决这个问题。各位仁兄帮个忙
解决方案 »
- 请问vs2008 SP1安装要注意哪些地方?
- 怎么把.c后缀的代码封成dll方便我c#调用?
- 求一方法完成ENTITY与Dicncy之间的转换,在线等!
- 页面上显示"[object]", 这个怎么回事????
- 求助?我该学些什么?真的很感谢你们
- C#中数据库操作可能出现的异常有哪些???谢谢
- MSSQL XML 查询是否有长度限制?
- 想在.net上找个硕士论文的题目做,各路高人指指路!! (散分)
- 为什么我从文件中读出来的鼠标光标是一块黑色的矩形???
- c#编写web services 的问题,请各位帮忙!!解决的给100噢,谢了!!!
- 世界上最难的SQL语句,搜虎的面试题,谁会啊。。。。!!!!!!!!!!!!!!!!!!!!!!!!
- privatePath这个属性能写绝对路径吗?
还好自己搞定了!
给自己加分了!???
请恕愚顿,看你的问题,自觉的确是有nums实现ILis接口的歧义
{
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>