Solved

Hide Select and Delete link buttons in asp.net gridview

Posted on 2010-11-17
5
429 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
  • 3
  • 2
5 Comments
 
LVL 12

Expert Comment

by:jagssidurala
Comment Utility
Before rendering the control hide two columns

GridView1.Columns[0].Visible = false;

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

Author Comment

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

Accepted Solution

by:
jagssidurala earned 500 total points
Comment Utility
before this line

GridView1.RenderControl(hw)

any where you can write.
0
 
LVL 9

Author Comment

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

Author Closing Comment

by:TonyReba
Comment Utility
perfect , that is what i was looking for!!
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Suggested Solutions

Envision that you are chipping away at another e-business site with a team of pundit developers and designers. Everything seems, by all accounts, to be going easily.
Although it can be difficult to imagine, someday your child will have a career of his or her own. He or she will likely start a family, buy a home and start having their own children. So, while being a kid is still extremely important, it’s also …
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
This video teaches users how to migrate an existing Wordpress website to a new domain.

771 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

11 Experts available now in Live!

Get 1:1 Help Now