如何设置边界在GridView控件的ItemTemplate [英] How to set border to ItemTemplates in GridView

查看:98
本文介绍了如何设置边界在GridView控件的ItemTemplate的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何设置的ItemTemplate边境GridView的?

How to set border for ItemTemplates in GridView?

以下是在GridView code。

Following is the Gridview code.

<div>
   <asp:GridView ID="GridView1" runat="server" 
    AutoGenerateColumns = "false" Font-Names = "Arial" 
    Font-Size = "11pt" AlternatingRowStyle-BackColor = "#C2D69B"  
    HeaderStyle-BackColor = "green" AllowPaging ="true"   
    OnPageIndexChanging = "OnPaging" OnRowDataBound = "RowDataBound"
    PageSize = "10" >
   <Columns>
    <asp:TemplateField>
        <HeaderTemplate>
            <asp:CheckBox ID="chkAll" runat="server" onclick = "checkAll(this);" />
        </HeaderTemplate> 
        <ItemTemplate>
            <asp:CheckBox ID="CheckBox1" runat="server" onclick = "Check_Click(this)"/>
        </ItemTemplate>
    </asp:TemplateField> 
    <asp:BoundField ItemStyle-Width = "150px" DataField = "CustomerID" HeaderText = "CustomerID" />
    <asp:BoundField ItemStyle-Width = "150px" DataField = "City" HeaderText = "City"/>
    <asp:BoundField ItemStyle-Width = "150px" DataField = "Country" HeaderText = "Country"/>
    <asp:BoundField ItemStyle-Width = "150px" DataField = "PostalCode" HeaderText = "PostalCode"/>
   </Columns> 
   <AlternatingRowStyle BackColor="#C2D69B"  />
</asp:GridView> 

所有的字段有界越来越边界但不是ItemTemplated领域。

All Bounded Fields are getting borders but not the ItemTemplated Fields.

推荐答案

一个解决方法是通过窃听到GridView的RowDataBound事件要做到这一点:

A workaround is to do this by tapping into the GridView's RowDataBound event:

protected void MyGrid_RowDataBound(object sender, GridViewRowEventArgs e)
{
     foreach (TableCell tc in e.Row.Cells)
     {
         tc.Attributes["style"] = "border-color: #c3cecc";
     }
}

此处了解详情:的 HTTP://$c$crsbarn.com/post/2009/05/31/Set-Color-of-GridLines-in-Gridview.aspx

请参阅评论部分为一个更好的办法...

See comments section for a better way...

protected void Page_Load(object sender, EventArgs e)
{
   this.GridView1.Attributes.Add("bordercolor", "c3cecc");
}

在GridView控件,声明BORDERCOLOR属性增加了一个内嵌样式声明只适用于表本身,而不是单个细胞。

"With the GridView, the declarative bordercolor attribute adds an inline style declaration which only applies to the table itself, not individual cells.

添加BORDERCOLOR属性编程不使用内联样式,而是使用HTML BORDERCOLOR属性,它的浏览器适用于表内的所有边界。

Adding the bordercolor attribute programmatically does not use an inline style, but uses the HTML bordercolor property, which browsers apply to ALL borders inside the table."

还有一件事,如果你使用的是Eric Meyer的重置,它打破在GridView表渲染。解决这一问题,特别是清除从重置规则表中的所有元素。

One more thing, if you are using Eric Meyer's reset, it breaks the table rendering in the GridView. Solution to that particular issue is to remove all table elements from the reset rule.

这篇关于如何设置边界在GridView控件的ItemTemplate的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆