Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 466
  • Last Modified:

Export to excel file from ASP.NET GridView with embedded dropdownlist.

Hello.

I am trying to export to excel from an ASP.NET GridView. I have a dropdownlist embedded in the gridview. When I make the DropDownList invisible in my aspx page the export works.  I have reviewed Expert Exchange Q_21055376.html. I am trying to implement the ClearControls routine so that I can have a visible dropdownlist except during the export process. I did a cut & paste and converted the C# code to VB.NET
using:
 '----------------------------------------------------------------
    ' Converted from C# to VB .NET using CSharpToVBConverter(1.2).
    ' Developed by: Kamal Patel (http://www.KamalPatel.net)
    '----------------------------------------------------------------

This is the converted code.

  Private Sub ClearControls(ByVal control As Control)
        Dim i As Integer
        For i = control.Controls.Count - 1 To 0 Step i - 1
            ClearControls(control.Controls(i))
        Next
        If TypeOf Not (control Is TableCell) Then                                  '  <----------##    !!
            'If Not (control Is TableCell) Then

            If Not control.GetType().GetProperty("SelectedItem") Is Nothing Then
                Dim literal As LiteralControl = New LiteralControl()
                control.Parent.Controls.Add(literal)
                Try
                    literal.Text = CType(control.GetType().GetProperty("SelectedItem").GetValue(control, Nothing), String)
                Catch
                End Try
                control.Parent.Controls.Remove(control)
            Else
                Dim literal As LiteralControl = New LiteralControl()
                control.Parent.Controls.Add(literal)
                literal.Text = CType(control.GetType().GetProperty("Text").GetValue(control, Nothing), String)
                control.Parent.Controls.Remove(control)
            End If
        End If
        Return
    End Sub

 I am getting the following error message on "TableCell". "TableCell" is a type and cannot be used as an expression. What is the proper VB conversion?
0
RonTrull
Asked:
RonTrull
1 Solution
 
Elvio Lujan.Net Senior DeveloperCommented:
       If Not control.GetType() = new TableCell.GetType() Then
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now