我的网站主页上有一个GridView。我想隐藏第一列:
这是网格视图。
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" BackColor="White" BorderColor="#999999" BorderStyle="Solid" BorderWidth="1px" CellPadding="3" DataSourceID="SqlDataSource4" ForeColor="Black" GridLines="Vertical" Height="300px" Width="1265px" AllowPaging="True" AllowSorting="True">
<AlternatingRowStyle BackColor="#CCCCCC" />
<Columns>
<asp:CommandField ShowSelectButton="True" SelectText="Add to Cart"></asp:CommandField>
<asp:BoundField DataField="ID_CARTE" HeaderText="Id" SortExpression="ID_CARTE" HeaderStyle-CssClass="hide-th" ItemStyle-CssClass="hide-td" />
<asp:BoundField DataField="Titlu" HeaderText="Titlu" SortExpression="Titlu" />
</Columns>
这是登录页面代码。我必须隐藏该列,因为它包含一个在ShoppingCart中添加商品的按钮,并且我希望用户仅在登录后才能添加商品。
Protected Sub LogIn(sender As Object, e As EventArgs)
If IsValid Then
' Validate the user password
Dim manager = Context.GetOwinContext().GetUserManager(Of ApplicationUserManager)()
Dim signinManager = Context.GetOwinContext().GetUserManager(Of ApplicationSignInManager)()
' This doen't count login failures towards account lockout
' To enable password failures to trigger lockout, change to shouldLockout := True
Dim result = signinManager.PasswordSignIn(Email.Text, Password.Text, RememberMe.Checked, shouldLockout := False)
Select Case result
Case SignInStatus.Success
If Request.QueryString("ReturnUrl") Is Nothing Then
IdentityHelper.RedirectToReturnUrl("/Carti", Response)
Else
IdentityHelper.RedirectToReturnUrl(Request.QueryString("ReturnUrl"), Response)
End If
答案 0 :(得分:0)
从不可见的列开始。登录后,找到该列并将其设置为可见。基本上:
GridView.Columns[0].Visible = true;
如果需要,请在SO中搜索如何从代码隐藏中显示/隐藏列。