您的位置:首页 > 其它

GridView常用的几个技巧

2006-07-22 09:14 387 查看

[ 2006-07-18 23:06:17 | 作者: Clingingboy ]

: | |
1.格式化
1.1根据字段格式化

void productsGridView_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
// determine the value of the UnitsInStock field
int unitsInStock = Convert.ToInt32(DataBinder.Eval(e.Row.DataItem, "UnitsInStock"));
if (unitsInStock == 0)
// color the background of the row yellow
e.Row.BackColor = Color.Yellow;
}
}





1.2定制外观.
GridView本身内制很多皮肤,你也可以在主题里自定义皮肤,然后再把皮肤导入

<%@ Page Language="C#" StyleSheetTheme="GridViewTheme" %>

接着再选自动套用格式,则出现你自己定义的样式





2.编辑

当你编辑时想使用web控件时,你必须先将字段转化为模板.还可以对字段的输入进行验证.同时为保持界面美观,你还可以设置控件的外观





3.删除

在删除之前先弹出确认窗口,不可以用默认的删除按钮,需用下面代码

<asp:LinkButton ID="LinkButton1" Runat="server" OnClientClick="return confirm('Are you sure you want to delete this record?');"
CommandName="Delete">Delete Order Line Item</asp:LinkButton>





4.显示图片

使用ImageField在控件中直接显示图片

<asp:ImageField DataImageUrlField="PictureURL"></asp:ImageField>





其实很多东西跟DataGrid差不多的.大家可以看微软的例子

下载例子

上面代码的例子全带有教程,不过是E文的,但大家只看代码多都少少会看的懂的,例子在哪呢.就在你的msdn帮助文件里.自己去找吧
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: