Thursday, July 28, 2011

How to export HTML table to Excel file

1
2
protected void Button1_Click(object sender, EventArgs e) { Response.Clear(); Response.AddHeader("content-disposition","attachment;filename=myexcel.xls"); Response.ContentType = "application/ms-excel"; System.IO.StringWriter sw = new System.IO.StringWriter(); System.Web.UI.HtmlTextWriter hw = new HtmlTextWriter(sw); mytable.RenderControl(hw); Response.Write(sw.ToString()); Response.End(); } public override void VerifyRenderingInServerForm(Control control) { }

Reference: Jessica Cao http://forums.asp.net/p/1086952/1625783.aspx

Monday, July 25, 2011

Display records information based on selected item from ComboBox in Access

Option Compare Database

Private Sub Form_Current()
    If Me.NewRecord Then
        Me.NameofTable = ""
    Else
        Me.NameofTable.SetFocus
        Me.NameofTable.Requery
        Me.NameofTable = Me.NameofTable.ItemData(Forms(0).CurrentRecord - 1)
    End If
End Sub

Private Sub NameofTable_Click()
    ' at this point, cbx text = cbx value
    If Me.NewRecord Or Me.NameofTable.ListIndex = -1 Then
         Me.nameoftabledum = Trim(Me.NameofTable)
         DoCmd.RunCommand acCmdSaveRecord
     Else
         If Me.NameofTable.ListIndex <> Forms(0).CurrentRecord - 1 Then
             DoCmd.GoToRecord , , acGoTo, Me.NameofTable.ListIndex + 1
         End If
    End If
End Sub

Private Sub NameofTable_KeyDown(KeyCode As Integer, Shift As Integer)
    If KeyCode = 46 Then
        If Me.NameofTable.SelLength < Len(Me.NameofTable.Value) Then
            ' delete part of the text
        Else   ' delete record
            Dim m As Integer
            m = Forms(0).CurrentRecord
            DoCmd.RunCommand acCmdDeleteRecord
            Me.NameofTable.Requery
            Forms(0).Requery
            If m > 1 Then m = m - 1
            DoCmd.GoToRecord , , acGoTo, m
         End If
    End If
End Sub


Friday, July 22, 2011

Retrieve RSS feeds and display in ASP.Net VB

Function ProcessRSSItem() As String
        Dim rssURL As String = "http://www.abc.com/rss.rss"

        Dim myRequest As WebRequest = System.Net.WebRequest.Create(rssURL)
        Dim myResponse As WebResponse = myRequest.GetResponse()

        Dim rssStream As Stream = myResponse.GetResponseStream()
        Dim rssDoc As New XmlDocument()
        rssDoc.Load(rssStream)

        Dim nsmg As New XmlNamespaceManager(rssDoc.NameTable)
        nsmg.AddNamespace("dc", "http://purl.org/dc/elements/1.1/")

        Dim rssItems As XmlNodeList = rssDoc.SelectNodes("rss/channel/item")

        Dim title As String = ""
        Dim link As String = ""
        Dim description As String = ""
        Dim i As Integer = 0
        Dim numItems As Integer = 1
        Dim sb As New System.Text.StringBuilder
        Dim rssDetail As XmlNode

        Do Until numItems = 10
            rssDetail = rssItems.Item(i).SelectSingleNode("dc:language", nsmg)
            Console.WriteLine(rssDetail.InnerText.ToString())
            If rssDetail.InnerText.Equals("en-US") Then
                rssDetail = rssItems.Item(i).SelectSingleNode("title")
                If rssDetail.Equals(Nothing) = False Then
                    title = rssDetail.InnerText
                Else
                    title = ""
                End If

                rssDetail = rssItems.Item(i).SelectSingleNode("link")
                If rssDetail.Equals(Nothing) = False Then
                    link = rssDetail.InnerText
                Else
                    link = ""
                End If

                rssDetail = rssItems.Item(i).SelectSingleNode("description")
                If rssDetail.Equals(Nothing) = False Then
                    description = rssDetail.InnerText
                Else
                    description = ""
                End If

                sb.Append("

" + title + "
") sb.Append(description + "

") numItems = i + 1 End If i = i + 1 Loop Return sb.ToString End Function

Wednesday, July 6, 2011

How to display all selected nodes in TreeVirw VB

    Private Sub btnUpdate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnUpdate.Click
        Dim names As String = ""
        Dim values As String = ""
        For Each parentNodes As TreeNode In trvIndustrySelections.Nodes
            For Each childNodes As TreeNode In parentNodes.Nodes
                If (childNodes.Checked) Then
                    names = childNodes.Text + "; " + names
                    values = childNodes.Name + "; " + values
                End If
            Next
        Next

        txtCurrentSelectNames.Text = names
        txtCurrentSelectValues.Text = values
    End Sub