如何循环设置DataGrid中某一列的内容,即我想更改邦定的内容,如数据库中是2,我想要它显示时为二星,不想通过SQL语句
转变,有没有其它方法

解决方案 »

  1.   

    DataGrid1.DataSource=ds;
    DataGrid1.DataBind();for(int i=0;i<DataGrid1.Items.Count;i++)
    {
    HtmlInputImage l=(HtmlInputImage)DataGrid1.Items[i].FindControl("name");
             string str=DataGrid1.Items[i].Cells[0].Text;
    if(str=="2")
    {
    l.Src="二星的图片路径";
    }
    }
      

  2.   

    foreach(DataGridItem row in this.DataGrid1.Items )
    {
    if(row.Cells[0].Text == "2")
    {
    row.Cells[0].Text = "★★";
    }
    }
      

  3.   

    或者:
    private void DataGrid1_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
    {
    if(e.Item.ItemIndex>-1)
    {
    if(e.Item.Cells[0].Text == "2")
    {
    e.Item.Cells[0].Text = "★★"; }
    }
    }
      

  4.   

    你完全可以在取出DataTable的时候就进行修改。
    for(int i=0;i<DataTable1.Rows.Count;i++)
    {
        if(DataTable1.Rows[i]["列名"] =="2")
        {
            DataTable1.Rows[i]["列名"] = "**"
        }
    }
      

  5.   

    DataGrid1_ItemDataBound
    写在这个事件里面,把你帮定的一个数据列转换成你要的图片就可以了,这个事件里面的代码是会循环的,不用自己写for的