Solved

Gridview Hide Delete on Certain Records but show empty column

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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

762 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

16 Experts available now in Live!

Get 1:1 Help Now