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