小弟用DataGridView绑定数据,运行显示出来,但是不符合我的要求;我想点击一行中的某个字段就会全部选择这一行,而不是选择这个字段(就是把一行都变蓝色,而不是这个字段显示蓝色),不知道我该怎么做?

解决方案 »

  1.   

    添加上事件private void DataGrid1_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
    {
    if(e.Item.ItemIndex==-1) return;
    e.Item.Attributes.Add("style","cursor:hand");
    e.Item.Attributes.Add("onMouseOver=this.style.backgroundColor","#add8ef");
    e.Item.Attributes.Add("onMouseOut=this.style.backgroundColor","");
    }
    你试一下,我做的比较简单!
      

  2.   

    不好意思 
    没发完
    int itemIndex=e.Item.ItemIndex;
    itemIndex=Convert.ToInt32(e.Item.Cells[0].Text,10);
    e.Item.Attributes.Add("onclick=this.style.backgroundColor","#f0f0f0");
    e.Item.Attributes.Add("onclick","<script> alert('"+itemIndex+"')</script>");
    }
      

  3.   

    this.dataGridView1.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
      

  4.   

    楼主说的是Web的,还是winForm的啊?winForm中设置属性:
    DataGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect;Web中楼上给了
      

  5.   

    this.dataGridView1.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
    dataGridView1 的属性里面有设置
    直接设置就完了