您的位置:首页 > 移动开发 > Objective-C

DataGrid中加多选按钮 和 鼠标移动显示不同的颜色

2010-10-19 16:21 501 查看
一、

aspx文件中加
<script language="javascript">
  <!--
  //CheckBox全选And反全选
  function select_deselectAll (chkVal, idVal)
  {
   var frm = document.forms[0];
   for (i=0; i<frm.length; i++)
   {
    if (idVal.indexOf ('CheckAll') != -1)
    {
     if(chkVal == true)
     {
      frm.elements[i].checked = true;
     }
     else
     {
      frm.elements[i].checked = false;
     }
    }
    else if (idVal.indexOf('DeleteThis') != -1)
    {
     if(frm.elements[i].checked == false)
     {
      frm.elements[1].checked = false;
     }
    }
   }
         }
   //-->
</script>

全选<input id="CheckAll" onclick="return select_deselectAll (this.checked, this.id)" tabIndex="0" type="checkbox" title="点击全选或反全选当前页所有信息">

DataGrid中加模板列
<asp:TemplateColumn HeaderText="选定">
<HeaderStyle Width="10%"></HeaderStyle>
<ItemTemplate>
<asp:CheckBox id="chkSelectBox" runat="server"></asp:CheckBox>
</ItemTemplate>
</asp:TemplateColumn>

CS文件中操作选定项
foreach (DataGridItem item in DataGrid.Items)
{
 if(((CheckBox)item.FindControl("chkSelectBox")).Checked==true)
 {
  Response.Write (item.Cells[0].Text);
 }
}

 

二、

 

核心代码:

private void grdCustomer_ItemDataBound(object sender,

         System.Web.UI.WebControls.DataGridItemEventArgs e)

{

     if(e.Item.ItemType == ListItemType.AlternatingItem ||

              e.Item.ItemType == ListItemType.Item )

     {

e.Item.Attributes.Add("onmouseover", "this.oldcolor=this.style.backgroundColor;this.style.backgroundColor='#C8F7FF'");

        e.Item.Attributes.Add("onmouseout", "this.style.backgroundColor=this.oldcolor");

          for (int i = 0; i< grdCustomer.Columns.Count; i++ )

              {

                   e.Item.Cells[i].Attributes.Add("onmouseover",

          "this.oldcolor=this.style.backgroundColor;this.style.backgroundColor='#99ccff'");

                   e.Item.Cells[i].Attributes.Add(

                       "onmouseout", "this.style.backgroundColor=this.oldcolor");

              }

     }

}

 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息