我是在一个自定义方法中想去把所有的dataField值取出来!我使用了
BoundColumn bc =  (BoundColumn)DataGrid1.Columns[i];
string s = bc.DataField; 
这样他的提示是异常详细信息: System.InvalidCastException: 指定的转换无效。 请给出解决办法,谢谢.

解决方案 »

  1.   

    用数组做,大概的思路如下;
    int n=0,i=DataGrid1.Columns.Count();
    BoundColumn bc =  (BoundColumn)DataGrid1.Columns[i];
    string [] s= new string[i]
    for(n=0;n<i;n++){
       s[i]=bc.DataField[i].ToString();
    }
      

  2.   

    int iIndex = MyDataGrid.SelectedIndex;//选择的行
    DataRow row = ds.Tables[0].Rows[iIndex];
    string   s = row[((BoundColumn)MyDataGrid.Columns[i]).DataField].ToString();
      

  3.   

    For i=0 to DataGrid1.Items.count-1 
      For j=0 to Datagrid1.cells.count-1
         Response.write(DataGrid1.Items(i).cells(j).text)
       
      Next
    Next