当单击DATAGRID   控件的某个位置时,能否使用这一行都变成其它的颜色,即此行被选中!   
  然后再读出这一行的数据到   TEXTBOX   控件中!   
  谢谢了 

解决方案 »

  1.   

    protected void GridViewReport_RowDataBound(object sender, System.Web.UI.WebControls.GridViewRowEventArgs e)
            {
                
                    //首先判断是否是数据行
                    if (e.Row.RowType == DataControlRowType.DataRow)
                    {
                        //当鼠标停留时更改背景色
                        e.Row.Attributes.Add("onmouseover", "c=this.className; this.className='GridSelelct'");                    //当鼠标移开时还原背景色
                        e.Row.Attributes.Add("onmouseout", "this.className=c");
                    }
                       }
      

  2.   

    不好意思刚才我打错了个字,当单击DATAGRID  控件的某个位置时,能否使用这一列都变成其它的颜色,即此行被选中!  
      然后再读出这一行的数据到  TEXTBOX  控件中!  
      谢谢了 
      

  3.   

    是列的数据不是行的数据,我做的是winform的程序
      

  4.   

    不好意思,准确说是2003版本,winform 程序,当datagrid里有6条记录时,用户点其中的一条,需要将这条记录的相关数据读出来,比如放到textbox里。 谢谢。
      

  5.   

    写DataGridView的CellClick事件就可以了
    private void dgvCInfo_CellClick(object sender, DataGridViewCellEventArgs e)
            {
                txtCName.Text = Convert.ToString(dgvCInfo[0, dgvCInfo.CurrentCell.RowIndex].Value).Trim();
                txtCManager.Text = Convert.ToString(dgvCInfo[1, dgvCInfo.CurrentCell.RowIndex].Value).Trim();
                txtCPhone.Text = Convert.ToString(dgvCInfo[2, dgvCInfo.CurrentCell.RowIndex].Value).Trim();        }
      

  6.   

    楼主的这种光棒效果可以这样实现
    protected void GridViewReport_RowDataBound(object sender, System.Web.UI.WebControls.GridViewRowEventArgs e) 
            { 
                
                   
                    if (e.Row.RowType == DataControlRowType.DataRow) 
                    { 
                        //当鼠标停留时更改背景色 
                        e.Row.Attributes.Add("onmouseover", "c=this.style.BackColor; this.style.BackColor='你希望的颜色'");                     //当鼠标移开时还原背景色 
                        e.Row.Attributes.Add("onmouseout", "this.style.BackColor=c"); 
                    } 
                      }关于选择的的话很简单 
    你就可以把你选择中的行里面的
    根据索引可以获得
      

  7.   

    我试了下,只能在GridView中实现楼主上面的方法,在DataGrid中没有RowDataBound事件,所以无法实现。