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

王朝asp·作者佚名  2006-01-09
窄屏简体版  字體: |||超大  

下面是使用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');

}

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
 
© 2005- 王朝網路 版權所有 導航