Solved

write HTML file from VB.NET

Posted on 2004-08-02
3
230 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

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

Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …

688 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