Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/281.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/29.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
在C#Asp Net 4中个性化GridView_C#_Asp.net_Gridview - Fatal编程技术网

在C#Asp Net 4中个性化GridView

在C#Asp Net 4中个性化GridView,c#,asp.net,gridview,C#,Asp.net,Gridview,这是从数据库填充的我的gridView: +---------+-------+----+---+ | Details | Combo | A | S | +---------+-------+----+---+ | View | PCM | 9 | 0 | | View | SAM | 14 | 0 | | View | RAS | 6 | 1 | | View | OUT | 14 | 2 | | View | Tot | 43 | 3

这是从数据库填充的我的gridView:

+---------+-------+----+---+
| Details | Combo | A  | S |
+---------+-------+----+---+
| View    | PCM   |  9 | 0 |
| View    | SAM   | 14 | 0 |
| View    | RAS   |  6 | 1 |
| View    | OUT   | 14 | 2 |
| View    | Tot   | 43 | 3 |
+---------+-------+----+---+
如果单击“视图”,我会在另一个aspx页面(GV.aspx)中获得行的详细信息

正如您在最后一行中看到的,我提供了列的总数

我需要删除最后一行中'Details'列中的'View',以获得此输出:

+---------+-------+----+---+
| Details | Combo | A  | S |
+---------+-------+----+---+
| View    | PCM   |  9 | 0 |
| View    | SAM   | 14 | 0 |
| View    | RAS   |  6 | 1 |
| View    | OUT   | 14 | 2 |
|         | Tot   | 43 | 3 |
+---------+-------+----+---+
你能帮我吗? 提前谢谢

这是我的ASPX页面中的GV

        <asp:GridView ID="GridView1" runat="server" AllowPaging="True" AutoGenerateColumns="False"
            ShowHeader="true" CssClass="mGrid" EmptyDataText="No Data"
            DataKeyNames="Combo" Width="500">
            <AlternatingRowStyle CssClass="altrows" />
            <Columns>
                <asp:TemplateField HeaderText="Details">
                    <ItemTemplate>
                        <asp:HyperLink ID="Link" runat="server" NavigateUrl='<%# string.Format("~/GV.aspx?Combo={0}", HttpUtility.UrlEncode(Eval("Combo").ToString()))  %>'
                            Text="View">
                        </asp:HyperLink>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:BoundField DataField="Combo" HeaderText="Combo" />
                <asp:BoundField DataField="A" HeaderText="A" />
                <asp:BoundField DataField="S" HeaderText="S" />
            </Columns>
        </asp:GridView>

您可以将
OnDataBound
事件添加到GridView中

OnDataBound="GridView1_DataBound"
这将在GridView将其所有行绑定到它之后触发。然后在该处理程序中,抓住最后一行并隐藏控件

protected void GridView1_DataBound(object sender, EventArgs e)
{
    GridViewRow row = GridView1.Rows[GridView1.Rows.Count - 1];
    HyperLink Link = (HyperLink)row.FindControl("Link");
    Link.Visible = false;
}

您可以在超链接中添加
Visible='
,如下所示:

<asp:GridView ID="GridView1" runat="server" AllowPaging="True" AutoGenerateColumns="False"
    ShowHeader="true" CssClass="mGrid" EmptyDataText="No Data"
    DataKeyNames="Combo" Width="500">
    <AlternatingRowStyle CssClass="altrows" />
    <Columns>
        <asp:TemplateField HeaderText="Details">
            <ItemTemplate>
                <asp:HyperLink ID="Link" runat="server" NavigateUrl='<%# string.Format("~/GV.aspx?Combo={0}", HttpUtility.UrlEncode(Eval("Combo").ToString()))  %>'
                    Text="View" Visible='<%#Eval("Combo").ToString() != "Total"%>'>
                </asp:HyperLink>
            </ItemTemplate>
        </asp:TemplateField>
    </Columns>
</asp:GridView>