p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   ASP.NET 2.0 Professional (http://p2p.wrox.com/forumdisplay.php?f=215)
-   -   Converting a given string to html table in asp,net (http://p2p.wrox.com/showthread.php?t=61880)

ostwald September 8th, 2007 01:20 PM

Converting a given string to html table in asp,net
Hi friends,
Can anyone help me abt this application.
I'm giving a html table string in a text box.(ex: <table><tr><td> ...............</tr></table>) as input.
And it must return me a datatable as an output and the values must be stored in database.
Plz help me this.


planoie September 9th, 2007 07:14 PM

If the HTML is XHTML compliant you could treat it as XML and get the rows and values from the table using an xml document and the right set of xpath queries. This would be a fairly elegant way to do it and would probably require the least amount of code. If you can't expect the input to conform to XHTML then you'll have to write a parser to handle more poorly formed input.


ostwald September 10th, 2007 04:44 AM

Hey Pete,
Thanx fo ur reply. I achieved the application by parsing. I didn'y use XHTML. I used html text as string and then parsed it to generate the required criteria. Herez the code.

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default4.aspx.cs" Inherits="Default4" ValidateRequest="false" %>
<%@ Import namespace="System.Text" %>
<%@ Import Namespace="System.IO" %>
<%@ Import Namespace="System.Data.SqlClient" %>
<%@ Import Namespace="System.Data" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Untitled Page</title>
<script language="C#" type="text/C#" runat=server >
private void Post_Text(object sender, EventArgs e)




postmess.Text=parsetext(mess.Text,false) ;

//postmess.Text=parsetext(mess.Text,true) ;

postmess.Text=mess.Text ;
String s = "Select * from htmln";
SqlConnection con = new SqlConnection("Data Source=KIRAN;Initial Catalog=TrylahNewLayout;Persist Security Info=True;User ID=sa;Password=sa123");
SqlDataAdapter da = new SqlDataAdapter(s,con);
SqlCommandBuilder cb = new SqlCommandBuilder(da);
DataSet ds = new DataSet("htmln");
da.Fill(ds, "htmln");

DataRow row = ds.Tables["htmln"].NewRow();
row["doc"] = postmess.Text;
da.Update(ds, "htmln");


public string parsetext(string text, bool allow)

StringBuilder sb = new StringBuilder(text) ;

sb.Replace(" "," &nbsp;");


sb.Replace("<","&lt;") ;
sb.Replace(">","&gt;") ;


StringReader sr = new StringReader(sb.ToString());
StringWriter sw = new StringWriter();


string temp = sr.ReadLine();

sw.Write(temp+"<br>") ;

return sw.GetStringBuilder().ToString();

<form runat=server ID="Form2">
<table border=1>
<td valign=top>Result</td>
<asp:label text="&nbsp;" id=postmess runat=server Width="68px" />
<tr><td valign=top>Enter Message </td>
<td><asp:textbox Columns="50" Rows="20" TextMode="MultiLine" id=mess runat=server /></td></tr>
<tr><td colspan=2 style="height: 28px"><asp:button onClick="Post_Text" text="Generate!" runat=server ID="Button1" /></td></tr>

All times are GMT -4. The time now is 12:19 PM.

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.