.net中DataGrid显示图片和修改颜色

类别:Asp 点击:0 评论:0 推荐:

下面是使用DataGrid的两个小技巧

一.如何改变DataGrid中某格的颜色

private void dgd_data_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
  {      
   if(e.Item.Cells[0].Text.Trim().Equals("AW"))
   {   
     e.Item.Cells[0].BackColor= System.Drawing.Color.Red;
   }
  }

二.当鼠标放到某格上的时候修改颜色

private void dgd_data_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
  {          
   e.Item.Cells[0].Attributes.Add("onmouseover", "this.style.backgroundColor='#DDEEFF'");      
  }

三.如何在DataGrid中显示图片

    <asp:TemplateColumn>
         <ItemStyle Width="22px"></ItemStyle>
         <ItemTemplate>
          <center>
           <img src='../Utility/UtilityPage/PictureBox.aspx?ItemCode=<%# DataBinder.Eval(Container.DataItem, "item_code") %>&CategoryCode=<%# DataBinder.Eval(Container.DataItem, "category_code") %>' width="20" height="15"  id='ItemCode=<%# DataBinder.Eval(Container.DataItem, "item_code") %>&CategoryCode=<%# DataBinder.Eval(Container.DataItem, "category_code") %>' onclick="OpenImage(id)">
          </center>
         </ItemTemplate>
        </asp:TemplateColumn>

    为DataGrid添加一个TemplateColumn

    其中PictureBox.aspx是一个显示图片的页面.

    当点图片的时候打开一个大的窗口显示图片

    function OpenImage(strCode){ 
    var strUrl = "../Utility/UtilityPage/PictureBox.aspx?" + strCode;
    window.open(strUrl,'Image','width=775,height=500,resizable=yes');              
   }

  

本文地址:http://com.8s8s.com/it/it8638.htm