Solved

Gridview Hide Delete on Certain Records but show empty column

Posted on 2013-01-23
3
270 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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…

733 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