日期:2014-05-20 浏览次数:20673 次
<img src="hello.gif" alt="hello" onerror="this.src='error.gif'" />
在某些情况下,DataGrid或者GridView的默认样式并不能满足日益高涨的用户的要求,很多人追求美观的样式。对表头设定背景也是其中的一个方面,那么有什么好的方法可以达到这一要求呢,我的方法如下:
DataGrid:
private void DataGrid1_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
{
if(e.Item.ItemType == System.Web.UI.WebControls.ListItemType.Header)
{
e.Item.Attributes.Add("style", "background-image:url('background.gif')");
}
}
GridView:
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.Header)
{
e.Row.Attributes.Add("style", "background-image:url('background.gif')");
}
}
------解决方案--------------------
我也来一个:在DataGrid和GridView中对表头设定背景图片,不需要后台代码。
<asp:GridView runat="server" ID="gvStatList" AllowPaging="false" Width="100%" CssClass="grid"
AutoGenerateColumns="false" Visible="true" ShowFooter="false">
<HeaderStyle CssClass="grid-head" />
</asp:GridView>
------解决方案--------------------
1.互斥对象.很多情况下存在互斥对象,我通常这么处理
bool showObject
{
set{
TextBox1.Visible=value;
TextBox2.Visible=!value;
}
}
------解决方案--------------------
<%=str%>
后台代码
变量
变量=@<img src='XXX' onclick='fucn(/)'>
foreach (DataRow dr_Child in dsResult1.Tables[0].Rows)
{
if (!Convert.ToBoolean(dr_Child["FLAG"]))
{
msiChild.sFontColor = "FontRed";
msiChild.BM = @"<img src='/Images/NowPostion1.gif' />" + msiChild.BM;
}
else if (Convert.ToBoolean(dr_Child["FLAG"]))
{
msiChild.BM = @"<img src='/Images/submit.gif' />" + msiChild.BM;
}
str += msiChild.BM;
}
return str;
------解决方案--------------------
Asp.Net2.0中我们可以方便的访问配置文件中,.NetFrameWork2.0新增加了 SystemWebSectionGroup 类。
允许用户以编程方式访问配置文件的 system.web 组。
比如判断web.config内是否为 debug="true",或者判断身份验证形式
SystemWebSectionGroup ws = new SystemWebSectionGroup();
CompilationSection cp = ws.Compilation;
用cp.Debug;就可以得到compilation节内关于"debug"的配置
AuthenticationSection as = ws.Authentication;
用 as.Mode 可以获取 authentication节中关于"mode"的配置,值为AuthenticationMode 枚举之一
AuthenticationMode的取值如下:
成员名称 说明
Forms 将基于 ASP.NET 窗体的身份验证指定为身份验证模式。
None 不指定身份验证。
Passport 将 Microsoft Passport 指定为身份验证模式。
Windows 将 Windows 指定为身份验证模式。在使用 Internet 信息服务 (IIS) 身份验证方法(基本、简要、集成 Windows (NTLM/Kerberos) 或证书)时适用此模式。
附:SystemWebSectionGroup 类的公共属性: