Solved

write HTML file from VB.NET

Posted on 2004-08-02
3
226 Views
Last Modified: 2012-05-05
Hi ,

I have my VB.NET writing the output in form of CSV file. Below is the code. It works fine and it gives me 20 records. Now I have to write the same content in form of HTML file with one thing extra. All the 20 rows will have one column "RecordIDFor1880" for which I have to give link. If user clicks it, it will open up some other page for which I know the path.
How can I achieve it?

Maha


Public Sub GenerateCSV()

        Try
            Dim OutputFileMSA As String = Application.StartupPath & "\CSVFiles\" & FirstLastName & ".csv"
            Dim myFileStream As New System.IO.FileStream(OutputFileMSA, _
           FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.None)
            'Create the stream writer
            Dim OutputFNMSA As New System.IO.StreamWriter(myFileStream)

            OutputFNMSA.WriteLine("Counter" & "," & "CountFromBlockedSet" & "," & "RecordIDFor1880" & "," & "FIRSTNAME" & "," & "LASTNAME" & "," & "Total Score")
            Dim connstr = "server=CSDAMAP1;uid=namematch;pwd=namematch;database=NameSearch;"
            Dim sqlConn4 As New SqlConnection(connstr)
            sqlConn4.Open()
            Dim rsSort_sqlcomm As New SqlCommand("SELECT * from ScoreTableNoQuotes order by TotalScore Desc", sqlConn4)
            Dim rsSortDR As SqlDataReader = rsSort_sqlcomm.ExecuteReader()
            Dim SortRecCount As Integer
            SortRecCount = 1

            While rsSortDR.Read()
                If SortRecCount <= 20 Then                  
                    OutputFNMSA.WriteLine(SortRecCount & "," & rsSortDR("CountFromBlockedSet") & "," & rsSortDR("RecordIDFor1880") & "," & rsSortDR("frstname") & "," & rsSortDR("lastname") & "," & rsSortDR("totalscore") & "," )
                    SortRecCount = SortRecCount + 1
                Else
                    Exit While
                End If
            End While

            OutputFNMSA.Close()
            OutputFNMSA = Nothing
            rsSortDR.Close()
            rsSortDR = Nothing
            sqlConn4.Close()
            sqlConn4 = Nothing
        Catch ex As Exception          
            MessageBox.Show(Err.Description, vbCritical, "JaroWeight")
        End Try
    End Sub
0
Comment
Question by:mahalakshmi_s
3 Comments
 
LVL 17

Accepted Solution

by:
AerosSaga earned 125 total points
ID: 11697920
Bind your datareader to a datagrid and then construct the columns like so where edit is the column you want to open with the link.

<asp:datagrid id="dg" runat="server" AllowPaging="True" GridLines="Horizontal" CellPadding="5"
                              AutoGenerateColumns="False" BorderColor="DarkGray" HorizontalAlign="Left" AllowSorting="True">
                              <AlternatingItemStyle BackColor="White"></AlternatingItemStyle>
                              <ItemStyle BackColor="WhiteSmoke"></ItemStyle>
                              <HeaderStyle Font-Bold="True"></HeaderStyle>
                              <Columns>
                                    <asp:TemplateColumn Visible="False" HeaderText="JobNumberID">
                                          <HeaderStyle Width="50px"></HeaderStyle>
                                          <ItemTemplate>
                                                <%# DataBinder.Eval(Container.DataItem, "JobNumberID") %>
                                          </ItemTemplate>
                                    </asp:TemplateColumn>
                                    <asp:TemplateColumn HeaderText="JobNumber">
                                          <HeaderStyle Width="50px"></HeaderStyle>
                                          <ItemTemplate>
                                                <%# DataBinder.Eval(Container.DataItem, "JobNumber") %>
                                          </ItemTemplate>
                                    </asp:TemplateColumn>
                                    <asp:TemplateColumn HeaderText="CustomerID">
                                          <HeaderStyle Width="50px"></HeaderStyle>
                                          <ItemTemplate>
                                                <%# DataBinder.Eval(Container.DataItem, "CustomerID") %>
                                          </ItemTemplate>
                                    </asp:TemplateColumn>
                                    <asp:TemplateColumn HeaderText="StartDate">
                                          <HeaderStyle Width="100px"></HeaderStyle>
                                          <ItemTemplate>
                                                <%# DataBinder.Eval(Container.DataItem, "StartDate", "{0:MM-dd-yy}") %>
                                          </ItemTemplate>
                                    </asp:TemplateColumn>
                                    <asp:TemplateColumn HeaderText="EndDate">
                                          <HeaderStyle Width="100px"></HeaderStyle>
                                          <ItemTemplate>
                                                <%# DataBinder.Eval(Container.DataItem, "EndDate", "{0:MM-dd-yy}") %>
                                          </ItemTemplate>
                                    </asp:TemplateColumn>
                                    <asp:TemplateColumn HeaderText="AssignedStaff">
                                          <HeaderStyle Width="150px"></HeaderStyle>
                                          <ItemTemplate>
                                                <%# DataBinder.Eval(Container.DataItem, "AssignedStaff") %>
                                          </ItemTemplate>
                                    </asp:TemplateColumn>
                                    <asp:TemplateColumn HeaderText="Description">
                                          <HeaderStyle Width="450px"></HeaderStyle>
                                          <ItemTemplate>
                                                <%# DataBinder.Eval(Container.DataItem, "Description") %>
                                          </ItemTemplate>
                                    </asp:TemplateColumn>
                                    <asp:TemplateColumn>
                                          <ItemStyle HorizontalAlign="Right"></ItemStyle>
                                          <ItemTemplate>
                                                <asp:LinkButton id="EditItem" runat="server" CommandName="Edit">Edit</asp:LinkButton>
                                          </ItemTemplate>
                                    </asp:TemplateColumn>
                              </Columns>
                              <PagerStyle PageButtonCount="20" Mode="NumericPages"></PagerStyle>
                        </asp:datagrid>

And then in the codebehind:

Private Sub dg_ItemCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles dg.ItemCommand
        If e.CommandName = "Edit" Then
            Response.Redirect("EditJob.aspx?jnid=" & CStr(dg.DataKeys(e.Item.ItemIndex)))
        End If
    End Sub

The CStr(dg.Datakeys(e.Item.ItemIndex))) will ensure your row selection

Regards,

Aeros
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

820 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