Solved

Gridview Hide Delete on Certain Records but show empty column

Posted on 2013-01-23
3
267 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
VB.net/WinForms: adjust Screen Resolution 6 44
Not showing page correctly 3 31
Close form "before" open 3 30
Get the selected ValueMember of Combobox 5 23
In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…
As a trusted technology advisor to your customers you are likely getting the daily question of, ‘should I put this in the cloud?’ As customer demands for cloud services increases, companies will see a shift from traditional buying patterns to new…

863 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

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now