如题:例如,列名为“姓名” 能不能取类似:“DataGrid1.ItemName["姓名"].ToString()”这样的数据?

解决方案 »

  1.   

    no, how did you bind the column to the datagrid? DataGrid doesn't remember 列名, if you used AutoGenerateColumns=true, you can try to figure the index of column, then normally, you can just doint n = ...;// index of the column
    foreach (DataGridItem dgi in DataGrid1.Items)
    {
      Response.Write(dgi.Cells[n].Text);
    }
      

  2.   

    不能那样取!
    应该这样:
    string str=DataGrid1.Items.Cells[列].Text;
      

  3.   

    那样是不能取值的。应该如下取:
    string sCellValue = DataGrid1.Items.Cells[cellIndex].Text;
      

  4.   

    if(e.Item.ItemType==ListItemType.Item||e.Item.ItemType==ListItemType.AlternatingItem)
    {  
     string youstring = e.Item.Cells[你的列明的索引].Text;
    }
      

  5.   

    string sCellValue = DataGrid1.Items[i].Cells[j].Text;
    string sCellValue = TextBox(DataGrid1.Items[i].Cells[j].Controls[0/1]).Text;
      

  6.   

    DataBinder.Eval(e.Item.DataItem, "UserName") 这种方法使用简单。
    ((DataRowView)(e.Item.DataItem))["UserName"] 这种方法执行效率高