datagrid 如何选中一行,选中的行背景颜色更改。

解决方案 »

  1.   

    背景色   
      private   void   DataGrid1_ItemCreated(object   sender,   System.Web.UI.WebControls.DataGridItemEventArgs   e)   
      {   
      if(e.Item.ItemIndex!=-1)   
      {   
      e.Item.Attributes.Add("onmouseover","this.setAttribute('BKC',this.style.backgroundColor);this.style.backgroundColor='#999999';this.style.cursor='hand';");   
      e.Item.Attributes.Add("onmouseout","this.style.backgroundColor=this.getAttribute('BKC');");   
      }
      

  2.   

    sub line_sel(id)
    on error resume next
    'window.mainform.selectId.value=id
    set obj=window.event.srcElement.ParentElement
    if not oldobj is nothing then
    if obj is oldobj then
    exit sub
    else
    oldobj.className=oldclass '"unselected"
    end if
    end if
    oldclass = obj.className
    obj.className="selected"
    set oldobj=obj
    window.mainForm.SelectedId.value=id'SelectedID是一个display:none的txtBox,我用它来记录当前选中的行的一个id
    end sub