Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/35.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在asp.net gridview中设置标题文本的样式_Asp.net_Gridview - Fatal编程技术网

在asp.net gridview中设置标题文本的样式

在asp.net gridview中设置标题文本的样式,asp.net,gridview,Asp.net,Gridview,问题1。我在网格视图中有一个超链接字段,如下所示: <asp:HyperLinkField Text="Analyze" /> 但这也不起作用 我基本上是在尝试将标题文本居中,没有什么特别之处,但这并没有发生。您必须将BodyContent中的代码替换为以下内容。 注意:您可以将自己的颜色添加到网格中 <asp:Content ID="BodyContent" ContentPlaceHolderID="MainContent" runat="server">

问题1。我在网格视图中有一个超链接字段,如下所示:

<asp:HyperLinkField  Text="Analyze" />
但这也不起作用


我基本上是在尝试将标题文本居中,没有什么特别之处,但这并没有发生。

您必须将BodyContent中的代码替换为以下内容。
注意:您可以将自己的颜色添加到网格中

<asp:Content ID="BodyContent" ContentPlaceHolderID="MainContent" runat="server">

    <style type="text/css">
        #MainContent_GridView2 tbody tr th {
            text-align: center;
            background: #808080;
            height: 40px;
        }

        #MainContent_GridView2 tbody tr {
            height: 20px;
            background-color: #CCC;
        }

            #MainContent_GridView2 tbody tr:hover {
                background-color: #808080;
            }

            #MainContent_GridView2 tbody tr td {
                text-align: center;
                height: 30px;
            }

        .linkfield {
            text-decoration: underline;
            text-align: center;
        }
    </style>

    <asp:GridView ID="GridView2"
        runat="server"
        AutoGenerateColumns="False"
        AllowPaging="True"
        AllowSorting="True"
        PageSize="25"
        Height="800px"
        Width="1200px"
        OnPageIndexChanging="GridView2_PageIndexChanging">
        <Columns>
            <asp:HyperLinkField DataNavigateUrlFields="runId" DataTextField="runId" HeaderText="RunID" DataNavigateUrlFormatString="RunAnalysis.aspx?runId={0}" ItemStyle-Width="10%">
                <ItemStyle Width="10%" CssClass="linkfield"></ItemStyle>
            </asp:HyperLinkField>
            <asp:BoundField DataField="prodDate" HeaderText="Date" DataFormatString="{0:MM/dd/yy}" ItemStyle-Width="10%">
                <ItemStyle Width="10%"></ItemStyle>
            </asp:BoundField>
            <asp:BoundField DataField="buildNumber" HeaderText="Build Number" ItemStyle-Width="10%">
                <ItemStyle Width="10%"></ItemStyle>
            </asp:BoundField>
            <asp:HyperLinkField DataNavigateUrlFields="PercentAnalysed" DataTextField="PercentAnalysed" HeaderText="Percent Analysed" ItemStyle-Width="10%">
                <ItemStyle Width="10%"></ItemStyle>
            </asp:HyperLinkField>
        </Columns>
        <PagerSettings FirstPageText="First" LastPageText="Last" NextPageText="Next" PreviousPageText="Previous" />
    </asp:GridView>
</asp:Content>


#主内容\u网格视图2 t车身tr th{
文本对齐:居中;
背景#8080;
高度:40px;
}
#主内容网格视图2 t车身tr{
高度:20px;
背景色:#CCC;
}
#MainContent_GridView2 t车身tr:悬停{
背景色:#808080;
}
#主内容网格视图2 t车身tr td{
文本对齐:居中;
高度:30px;
}
林菲尔德先生{
文字装饰:下划线;
文本对齐:居中;
}

希望这有帮助。

您是否尝试修改网格列属性中的位置?您所说的“位置”是什么意思?很抱歉,我没有收到您的信息。您可以使用gridview中的“编辑列”选项来获取列属性。这样,您就可以在项目样式中设置该控件的水平对齐方式。它适用于所有字段,但不适用于标题文本。您是否可以按预期放置gridview的图像?如果您需要进一步更改,请告诉我:是为了这个吗?这段代码给出了一些内容页错误。你用过母版页吗?不,实际上它主要是为了满足你的需要,将标题文本居中对齐。是的,我在这里使用的代码来自你发送的链接。做适当的改变
<asp:Content ID="BodyContent" ContentPlaceHolderID="MainContent" runat="server">

    <style type="text/css">
        #MainContent_GridView2 tbody tr th {
            text-align: center;
            background: #808080;
            height: 40px;
        }

        #MainContent_GridView2 tbody tr {
            height: 20px;
            background-color: #CCC;
        }

            #MainContent_GridView2 tbody tr:hover {
                background-color: #808080;
            }

            #MainContent_GridView2 tbody tr td {
                text-align: center;
                height: 30px;
            }

        .linkfield {
            text-decoration: underline;
            text-align: center;
        }
    </style>

    <asp:GridView ID="GridView2"
        runat="server"
        AutoGenerateColumns="False"
        AllowPaging="True"
        AllowSorting="True"
        PageSize="25"
        Height="800px"
        Width="1200px"
        OnPageIndexChanging="GridView2_PageIndexChanging">
        <Columns>
            <asp:HyperLinkField DataNavigateUrlFields="runId" DataTextField="runId" HeaderText="RunID" DataNavigateUrlFormatString="RunAnalysis.aspx?runId={0}" ItemStyle-Width="10%">
                <ItemStyle Width="10%" CssClass="linkfield"></ItemStyle>
            </asp:HyperLinkField>
            <asp:BoundField DataField="prodDate" HeaderText="Date" DataFormatString="{0:MM/dd/yy}" ItemStyle-Width="10%">
                <ItemStyle Width="10%"></ItemStyle>
            </asp:BoundField>
            <asp:BoundField DataField="buildNumber" HeaderText="Build Number" ItemStyle-Width="10%">
                <ItemStyle Width="10%"></ItemStyle>
            </asp:BoundField>
            <asp:HyperLinkField DataNavigateUrlFields="PercentAnalysed" DataTextField="PercentAnalysed" HeaderText="Percent Analysed" ItemStyle-Width="10%">
                <ItemStyle Width="10%"></ItemStyle>
            </asp:HyperLinkField>
        </Columns>
        <PagerSettings FirstPageText="First" LastPageText="Last" NextPageText="Next" PreviousPageText="Previous" />
    </asp:GridView>
</asp:Content>