We help IT Professionals succeed at work.

Post back to table

rckrch
rckrch used Ask the Experts™
on
I am trying to change a vb.net generated gridview in an asp.net page with the index change of a drop down list using ViewState and autopostback.  The initally loads fine and displays all that is in the page, but when I change the selection on the drop down list on the page I get 'Internet Explorer cannot display web page'.  

Any help would be greatly appreciated.

Thanks


Below is the code:

<asp:DropDownList ID="ByteDataFile" runat="server" Width="100%"
                        BackColor="#336699" Font-Bold="True" Font-Names="Arial"
                        Font-Size="Small" ForeColor="#FFFFCC" CssClass="DropDnBorderTrans"
                        AutoPostBack="True">
                        </asp:DropDownList>
'Page Load

If IsPostBack Then
            LineNo = DropDownList4.SelectedValue

            ByteDataTable = ViewState("DTable")
            ByteDataFile.SelectedValue = ViewState("TableFile")
            FileNameID = ByteDataFile.SelectedValue
           
        Else
            Dim PathString As String = "\\..." & LineNo & "\Text Files\"
            Dim di As DirectoryInfo = New DirectoryInfo("\\..." & LineNo & "\Text Files\")  
            Dim Files As FileInfo() = di.GetFiles()
            FileNameID = di.GetFiles.GetValue(0).ToString
            ByteDataFile.DataSource = Files
            ByteDataFile.DataBind()
        End If

Dim TextDelimiter As Char = ControlChars.Tab

                Using sr As FileIO.TextFieldParser = New FileIO.TextFieldParser("\\..." & LineNo & "\Text Files\" & FileNameID) With {.Delimiters = {vbTab}}
            While Not sr.EndOfData
                Dim LineX = sr.ReadFields().ToArray
                If LineX(0).Trim = "Key:" Then
                    ByteDataTable.Columns.Add("Data And Time")
                    For Each x In LineX
                        If x.Trim = "Key:" OrElse String.IsNullOrEmpty(x.Trim) Then Continue For
                        ByteDataTable.Columns.Add(New DataColumn With {.ColumnName = x.Trim.Replace(" ", "_")})
                        xBool = True
                    Next
                    Continue While
                End If
                If Not xBool OrElse LineX.Count < ByteDataTable.Columns.Count Then Continue While
                Dim dr As DataRow = ByteDataTable.NewRow()
                For x = 0 To ByteDataTable.Columns.Count - 1
                    dr.Item(x) = LineX(x).Trim
                Next
                ByteDataTable.Rows.Add(dr)
            End While
        End Using
MAKEGRID:

        BytewiseGrid.DataSource = ByteDataTable
        BytewiseGrid.DataBind()


'Drop Down List Change even
Protected Sub ByteDataFile_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs) Handles ByteDataFile.SelectedIndexChanged
        BytewiseGrid = Nothing

        Dim TextDelimiter As Char = ControlChars.Tab
        Dim LineNo As String = DropDownList4.SelectedValue
        Dim FileNameID As String = ByteDataFile.SelectedValue
        Dim ByteDataTable As DataTable = New DataTable, xBool As Boolean = False

        Using sr As FileIO.TextFieldParser = New FileIO.TextFieldParser("\\..." & LineNo & "\Text Files\" & FileNameID) With {.Delimiters = {vbTab}}
            While Not sr.EndOfData
                Dim LineX = sr.ReadFields().ToArray
                If LineX(0).Trim = "Key:" Then
                    ByteDataTable.Columns.Add("Data And Time")
                    For Each x In LineX
                        If x.Trim = "Key:" OrElse String.IsNullOrEmpty(x.Trim) Then Continue For
                        ByteDataTable.Columns.Add(New DataColumn With {.ColumnName = x.Trim.Replace(" ", "_")})
                        xBool = True
                    Next
                    Continue While
                End If
                If Not xBool OrElse LineX.Count < ByteDataTable.Columns.Count Then Continue While
                Dim dr As DataRow = ByteDataTable.NewRow()
                For x = 0 To ByteDataTable.Columns.Count - 1
                    dr.Item(x) = LineX(x).Trim
                Next
                ByteDataTable.Rows.Add(dr)
            End While
        End Using

        BytewiseGrid.DataSource = ByteDataTable
        BytewiseGrid.DataBind()
        ViewState("DTable") = ByteDataTable
        ViewState("TableFile") = ByteDataFile.SelectedValue



    End Sub
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Most Valuable Expert 2012
Top Expert 2014
Commented:
So you populate a gridview from a different text file based on selection in drop down?

Did you step through the code to see what's happening?

Why do you have

BytewiseGrid = Nothing

in selectedindexchanged?

Author

Commented:
Thanks codecruiser for the reply.  Sorry it took me so long to get back to you.  I changed the code to use a page control that is updated during postback.  It works now without using viewstate.  I was trying to simply use the input value as the parameter criteria for the file search.  

Another problem I was having is that the files are so large I would get a 'Internet Explorer cannot display the web page' message.  I changed that too and it worked.
Most Valuable Expert 2012
Top Expert 2014

Commented:
Good to know that you fixed the issue :-)