Solved

Gridview Hide Delete on Certain Records but show empty column

Posted on 2013-01-23
3
269 Views
Last Modified: 2013-02-04
I have the following and it works, but it removes the column when there is no Delete link.  I would like the column to show, but be empty when there is no delete link.


What the gridview is doing
 Protected Sub txtAddendum_RowDataBound(sender As Object, e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles txtAddendum.RowDataBound
        If e.Row.RowType = DataControlRowType.DataRow Then
            Dim drv As DataRowView = TryCast(e.Row.DataItem, DataRowView)
            If drv("OrdersAddendum").ToString().Equals("0") Then
                e.Row.Cells(0).Visible = False
            Else
                e.Row.Cells(0).Visible = True
            End If
        End If
    End Sub

Open in new window

0
Comment
Question by:rcowen00
3 Comments
 
LVL 83

Accepted Solution

by:
CodeCruiser earned 500 total points
ID: 38812217
Change this

 e.Row.Cells(0).Visible = False

to either

 e.Row.Cells(0).Style("display")="none"

or

 e.Row.Cells(0).Value=""
0
 
LVL 9

Expert Comment

by:psgindiana
ID: 38812222
instead of
e.Row.Cells(0).Visible = False

Open in new window

use:
            foreach (Control c in e.Row.Cells(0).Controls)
            {
                 c.Visible = False;
            }

Open in new window

which should keep the table structure but hide the controls inside the cell.

** this is c#. I don't know VB enough not to jack up some syntax. You should be able to figure out how it's working, though, and fix it accordingly ("Dim c As Control" instead of "Control c", etc.)
0
 
LVL 41

Expert Comment

by:guru_sami
ID: 38812418
I use a TemplateField for setting visibility like:

<asp:TemplateField HeaderText="Delete" HeaderStyle-Width="30px" HeaderStyle>
                <ItemTemplate>
                    <asp:LinkButton ID="DeleteButton" runat="server" CommandName= "Delete"   Visible='<%#IsVisible(Eval("IsPending"))%>' />
                   </ItemTemplate>
</asp:TemplateField>

Open in new window

In Code-behind IsVisible method looks like this:

Public Function IsVisible(ispending As Object) As Boolean
	Return Not CBool(ispending)
        'You can use any logic here to determine whether to return true or false
End Function

Open in new window

0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
transaction in asp.net, sql server 6 43
ASP.NET Content Page 3 30
asp Google Map 2 32
Adding items to a C# list incrementally 5 33
In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

829 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question