Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Professional
| Search | Today's Posts | Mark Forums Read
ASP.NET 2.0 Professional If you are an experienced ASP.NET programmer, this is the forum for your 2.0 questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Professional section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old September 8th, 2007, 01:20 PM
Authorized User
 
Join Date: Jun 2007
Location: hyderabad, AndhraPradesh, India.
Posts: 24
Thanks: 0
Thanked 0 Times in 0 Posts
Default 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.

regards
Ossy!
__________________
Surya!
 
Old September 9th, 2007, 07:14 PM
planoie's Avatar
Friend of Wrox
Points: 16,481, Level: 55
Points: 16,481, Level: 55 Points: 16,481, Level: 55 Points: 16,481, Level: 55
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2003
Location: Clifton Park, New York, USA.
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

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.

-Peter
 
Old September 10th, 2007, 04:44 AM
Authorized User
 
Join Date: Jun 2007
Location: hyderabad, AndhraPradesh, India.
Posts: 24
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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>
</head>
<script language="C#" type="text/C#" runat=server >
private void Post_Text(object sender, EventArgs e)
{

if(mess.Text!="")
{

if(parse.Checked)
{

if(htmlpost.Checked)
{

postmess.Text=parsetext(mess.Text,false) ;
}
else
{

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

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;
ds.Tables["htmln"].Rows.Add(row);
da.Update(ds, "htmln");



}
}

public string parsetext(string text, bool allow)
{

StringBuilder sb = new StringBuilder(text) ;

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

if(!allow)
{

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

sb.Replace("\"","&quot;");
}

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

while(sr.Peek()>-1)
{

string temp = sr.ReadLine();

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

return sw.GetStringBuilder().ToString();
}
</script>
<body>


<center>
<br>
<form runat=server ID="Form2">
<table border=1>
<tr>
<td valign=top>Result</td>
<td>
<asp:label text="&nbsp;" id=postmess runat=server Width="68px" />
</td></tr>
<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>
</table>
</form>
</center>
</body>
</html>




Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem Converting C# to VB.NET in ASP.NET kwilliams ASP.NET 2.0 Basics 0 February 9th, 2007 06:22 PM
Converting an HTML Form to ASP.Net Form k_alidxb75 ASP.NET 1.x and 2.0 Application Design 0 November 30th, 2006 03:26 AM
converting the string to integer vb .net 2005 Subjugate .NET Framework 2.0 1 November 25th, 2006 02:18 PM
return a string with all HTML and ASP tags strippe ccc_storage ASP.NET 1.x and 2.0 Application Design 2 September 23rd, 2004 10:43 PM





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