Solved

Hide Select and Delete link buttons in asp.net gridview

Posted on 2010-11-17
5
439 Views
Last Modified: 2012-05-10
I am using a code to export my gridview to excel, everything works great both I dont want to disaplay first to columns in my excel exported file...

any suggestions?

Protected Sub btnExportExcel_Click(ByVal sender As Object, ByVal e As EventArgs)

        Response.Clear()
        Response.Buffer = True
        Response.AddHeader("content-disposition", "attachment;filename=PhysicianConcerns.xls")
        Response.Charset = ""
        Response.ContentType = "application/vnd.ms-excel"


        Dim sw As New StringWriter()
        Dim hw As New HtmlTextWriter(sw)
        GridView1.AllowPaging = False
        GridView1.AllowSorting = False
        GridView1.DataBind()


        'Change the Header Row back to white color 
        GridView1.HeaderRow.Style.Add("background-color", "#FFFFFF")


        'Apply style to Individual Cells 

        GridView1.HeaderRow.Cells(2).Style.Add("background-color", "teal")
        GridView1.HeaderRow.Cells(3).Style.Add("background-color", "teal")
        GridView1.HeaderRow.Cells(4).Style.Add("background-color", "teal")
        GridView1.HeaderRow.Cells(5).Style.Add("background-color", "teal")
        GridView1.HeaderRow.Cells(6).Style.Add("background-color", "teal")
        GridView1.HeaderRow.Cells(7).Style.Add("background-color", "teal")
        GridView1.HeaderRow.Cells(8).Style.Add("background-color", "teal")
        GridView1.HeaderRow.Cells(9).Style.Add("background-color", "teal")
        GridView1.HeaderRow.Cells(10).Style.Add("background-color", "teal")


        ' Find controls to hide

        Dim Links As LinkButton = GridView1.HeaderRow.Cells(0).FindControl("LinkButton1")

        Links.Enabled = False


        For i As Integer = 2 To GridView1.Rows.Count - 1

            Dim row As GridViewRow = GridView1.Rows(i)
            'Change Color back to white 
            row.BackColor = System.Drawing.Color.White
            'Apply text style to each Row 
            row.Attributes.Add("class", "textmode")

        Next

        GridView1.RenderControl(hw)

        'style to format numbers to string 

        Dim style As String = "<style>.textmode{mso-number-format:\@;}</style>"
        Response.Write(style)
        Response.Output.Write(sw.ToString())
        Response.Flush()
        Response.End()

    End Sub

Open in new window

0
Comment
Question by:TonyReba
[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
  • 2
5 Comments
 
LVL 12

Expert Comment

by:jagssidurala
ID: 34157837
Before rendering the control hide two columns

GridView1.Columns[0].Visible = false;

GridView1.Columns[1].Visible = false;
0
 
LVL 9

Author Comment

by:TonyReba
ID: 34158069
Can you tell me in what lines do I need to place this?
0
 
LVL 12

Accepted Solution

by:
jagssidurala earned 500 total points
ID: 34158130
before this line

GridView1.RenderControl(hw)

any where you can write.
0
 
LVL 9

Author Comment

by:TonyReba
ID: 34158452
Can you tell me in what lines do I need to place this?
0
 
LVL 9

Author Closing Comment

by:TonyReba
ID: 34159594
perfect , that is what i was looking for!!
0

Featured Post

Secure Your WordPress Site: 5 Essential Approaches

WordPress is the web's most popular CMS, but its dominance also makes it a target for attackers. Our eBook will show you how to:

Prevent costly exploits of core and plugin vulnerabilities
Repel automated attacks
Lock down your dashboard, secure your code, and protect your users

Question has a verified solution.

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

An enjoyable and seamless user experience can go a long way on an eCommerce site. While a cohesive layout and engaging copy play roles in creating a positive user experience, some sites neglect aspects that seem marginal but in actuality prove very …
Color can increase conversions, create feelings of warmth or even incite people to get behind a cause. If you want your website to really impact site visitors, then it is vital to consider the impact color has on them.
The viewer will learn how to count occurrences of each item in an array.
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

696 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