different table with same with - c#

I am dynamically generating tables one after another using asp.net c#.I have different section in a table
td.section{width:200px;}
<table>
<tr>
<td colspan="2" class="section">Sec 1</td>
</tr>
<tr>
<td>1</td>
<td>s</td>
</tr>
</table>
<table>
<tr>
<td class="section">Sec 2</td>
</tr>
<tr>
<td>1</td>
</tr>
</table>
<table>
<tr>
<td colspan="3" class='section'>Sec 3</td>
</tr>
<tr>
<td colspan="3">1</td>
</tr>
<tr>
<td>1</td>
<td>1</td>
<td>1</td>
</tr>
</table>
I want each sections must be same with but I am unable to do this.Can you guide me how can I do this.

I added the width attribute at the top within a style tag and I think I got what you're aiming for. Note that width is spelled with a "d" and you are also missing a "<" on your second tag.
Finished product:
<style>
td.section{width:200px;}
</style>
<table>
<tr>
<td colspan='2' class='section'>Sec 1</td>
</tr>
<tr>
<td>1</td>
<td>s</td>
</tr>
</table>
<table>
<tr>
<td class='section'>Sec 2</td>
</tr>
<tr>
<td>1</td>
</tr>
</table>
<tr>
<td colspan='3' class='section'>Sec 3</td>
</tr>
<tr>
<td>1</td>
</tr>
</tr>
<tr>
<td>1</td>
<td>1</td>
<td>1</td>
</tr>
</table>

Related

Remove table row that have empty cells c#

I have a table created from a WYSIWYG editor and save as a string in C#. When I submit a form, I will map the values to the table cells. However, there are some empty rows that don't have any data. How can I remove these rows, for example the 3 4 row, before returning the html string with either regex or HtmlAgilityPack? Thanks
The table in the string looks like this:
<table>
<thead>
<tr>
<th></th>
<th>Name</th>
<th>Age</th>
</tr>
</thead>
<tbody>
<tr>
<td>1</td>
<td>John</td>
<td>18</td>
</tr>
<tr>
<td>2</td>
<td>Arthur</td>
<td>20</td>
</tr>
<tr>
<td>3</td>
<td></td>
<td></td>
</tr>
<tr>
<td>4</td>
<td></td>
<td></td>
</tr>
</tbody>
</table>
Preview:
It's better to manage the empty elements on the frontend than the backend because you don't need to submit them and process them on the backend if you can simply filter them out (or even better validate them before submitting) on the frontend.
Proof-of-concept with JS:
const cells = document.querySelectorAll('td');
const emptyCells = Array.from(cells).filter(cell => cell.innerHTML === '');
emptyCells.forEach(cell => cell.parentNode.remove());
<table>
<thead>
<tr>
<th></th>
<th>Name</th>
<th>Age</th>
</tr>
</thead>
<tbody>
<tr>
<td>1</td>
<td>John</td>
<td>18</td>
</tr>
<tr>
<td>2</td>
<td>Arthur</td>
<td>20</td>
</tr>
<tr>
<td>3</td>
<td></td>
<td></td>
</tr>
<tr>
<td>4</td>
<td></td>
<td></td>
</tr>
</tbody>
</table>

Table to datagridview

How to convert html table to datagridview in C#?
Let me know any reference for conversion.
Here is Html table.
<table>
<tr>
<td>Living Room</td>
</tr>
<tr>
<td>Size</td>
<td>Quantity</td>
<td>Amount</td>
<td>Duration</td>
</tr>
<tr>
<td>1</td>
<td>1</td>
<td>1</td>
<td>1</td>
</tr>
<tr>
<td>2</td>
<td>2</td>
<td>2</td>
<td>2</td>
</tr>
</table>

Split a string based on delimiters and insert splits into table as rows

I have a string is as follows:
L1N:0V L2N:0V L3N:0V L12:0V L23:0V L31:0V IL1:0A IL2:0A IL3:0A RPM:0 FREQ:0.00Hz P:0.00psi T:64'C Fuel:43% kVA:0 BVolt:27.00V Hrs:2272
I am interested in the splits that are bold in the following string
L1N:0V L2N:0V L3N:0V L12:0V L23:0V L31:0V IL1:0A IL2:0A IL3:0A RPM:0 FREQ:0.00Hz P:0.00psi T:64'C Fuel:43% kVA:0 BVolt:27.00V Hrs:2272
And I want to create multiple rows for each of these splits as shown below.
<table>
<tr>
<td>ID</td>
<td>Value</td>
</tr>
<tr>
<td>1</td>
<td>0</td>
</tr>
<tr>
<td>2</td>
<td>0</td>
</tr>
<tr>
<td>3</td>
<td>0</td>
</tr>
<tr>
<td>4</td>
<td>0</td>
</tr>
<tr>
<td>5</td>
<td>0</td>
</tr>
<tr>
<td>6</td>
<td>0</td>
</tr>
<tr>
<td>7</td>
<td>0</td>
</tr>
<tr>
<td>8</td>
<td>0</td>
</tr>
<tr>
<td>9</td>
<td>0</td>
</tr>
<tr>
<td>10</td>
<td>0</td>
</tr>
<tr>
<td>11</td>
<td>0</td>
</tr>
<tr>
<td>12</td>
<td>0</td>
</tr>
<tr>
<td>13</td>
<td>64</td>
</tr>
<tr>
<td>14</td>
<td>43</td>
</tr>
<tr>
<td>15</td>
<td>0</td>
</tr>
<tr>
<td>16</td>
<td>27</td>
</tr>
<tr>
<td>17</td>
<td>2272</td>
</tr>
</table>
While agreeing with the comments above, try this for starters:
string[] substring = myString.Split(':');
foreach (string str in substrings){
if(!string.IsNullOrEmpty(str){
var val = double.tryParse(str);
}
}
And then use those values for your html (in javascript it would be something like
var table = document.getElementById('myTable');
var row = table.insertRow(0);
cell1 = row.insertCell(0);
cell1.innerHTML = val;

Webrowser manipulate HTML Table

I'm trying to manipulate a html table open in webbrowser control, this tool will be used ti access a sharepoint page with an autologin option. This far this is what i have:
HtmlElementCollection htmlcol =
wb.Document.GetElementsByTagName("formTextfield277");
for (int i = 0; i < htmlcol.Count; i++)
{
if (htmlcol[i].Name == "portal_id")
{
htmlcol[i].SetAttribute("VALUE",
Properties.Settings.Default.sharepoint_user);
}
else if (htmlcol[i].Name == "password")
{
htmlcol[i].SetAttribute("VALUE",
Properties.Settings.Default.sharepoint_pw);
}
}
This C# code if for manipulate this HTML page:
<TABLE CELLSPACING="0" CELLPADDING="0" WIDTH="100%" BORDER="0">
<TR>
<TD CLASS="txtRedBold10" WIDTH="4"> </TD>
<TD CLASS="txtRedBold10" COLSPAN="2" HEIGHT="30">Please log in</TD>
</TR>
<TR>
<TD CLASS="txtBlackReg10" WIDTH="4"> </TD>
<TD CLASS="txtBlackReg10">Username:</TD>
<TD><INPUT CLASS="formTextfield277" TYPE="text" NAME="portal_id" VALUE="" VCARD_NAME="vCard.Email" SIZE="28"></TD>
</TR>
<TR>
<TD CLASS="txtBlackReg10" COLSPAN="3"> </TD>
</TR>
<TR>
<TD CLASS="txtBlackReg10" COLSPAN="2"> </TD>
<TD CLASS="txtBlackReg10">Please enter your username or E-Mail Address</TD>
</TR>
<TR>
<TD CLASS="txtBlackReg10" COLSPAN="3"> </TD>
</TR>
<TR>
<TD CLASS="txtBlackReg10" WIDTH="4"> </TD>
<TD CLASS="txtBlackReg10">Password:</TD>
<TD><INPUT CLASS="formTextfield277" TYPE="password" NAME="password" SIZE="28" AUTOCOMPLETE="off"></TD>
</TR>
<TR>
<TD CLASS="txtBlackReg10" COLSPAN="3"> </TD>
</TR>
<TR>
<TD CLASS="txtBlackReg10" COLSPAN="2"> </TD>
<TD CLASS="txtBlackReg10">Please enter your network or Intranet password</TD>
</TR>
<TR>
<TD CLASS="txtBlackReg10" COLSPAN="3"> </TD>
</TR>
<TR>
<TD CLASS="txtBlackReg10" COLSPAN="2"> </TD>
<TD CLASS="txtBlackReg10">
<TABLE CELLSPACING="0" CELLPADDING="0" BORDER="0">
<TR>
<TD><INPUT TYPE="image" HEIGHT="24" WIDTH="20" SRC="images/cp_arrow.gif" VALUE="Log In"
BORDER="0"></TD>
<TD><A CLASS="linkTxtRedBold10" HREF="javascript:signin()"
onClick="saveForm()">Login</A>
</TD>
</TR>
</TABLE>
</TD>
</TR>
<TR>
<TD CLASS="txtBlackReg10" COLSPAN="3"> </TD>
</TR>
</TABLE>
Any sugestions?
Thanks in advance!
wb.Document.GetElementsByTagName("input") not wb.Document.GetElementsByTagName("formTextfield277");
HtmlElementCollection inputHtmlCollection = Document.GetElementsByTagName("input");
foreach (HtmlElement anInputElement in inputHtmlCollection)
{
if (anInputElement.Name.Equals("portal_id"))
{
anInputElement.SetAttribute("VALUE", Properties.Settings.Default.sharepoint_user);
}
if (anInputElement.Name.Equals("password"))
{
anInputElement.SetAttribute("VALUE", roperties.Settings.Default.sharepoint_pw);
}
}
hope this help!

How to use Majestic13 for parsing HTML?

I have a HTML document of the structure
<table width="85%" border="1" height="315" align="center">
<tr>
<td colspan="2" align="center"><font color="#400040"><b>Register No</b></font></td>
<th colspan="2"><font color="Brown">42209104069</font></th>
<td colspan="2" align="center"><font color="#400040"><b>Name</b></font></td>
<th colspan="2"><font color="Brown">SATHISH KUMAR R</font></th>
</tr>
<tr>
<td colspan="2"><font color="blue"><center><b>Subject</b></font></td>
<td colspan="2"><font color="blue"><center><b>Credits</b></font></td>
<td colspan="2"><font color="blue"><center><b>Grade</b></font></td>
<td colspan="2"><font color="blue"><center><b>Result</b></font></td>
</tr>
<tr>
<td colspan="2"><center> CS2301</td> //1
<td colspan="2"><center> 3</td> //2
<td colspan="2"><center> E</td> //3
<td colspan="2"><center> PASS</td> //4
</tr>
</table>
I want to extract the contents of the tag of lines 1,2,3,4 and save to a string. I want to know how to achieve this using Majestic13 in my C# project.
PM> Install-Package Majestic13
var html=#"<table width="85%" border="1" height="315" align="center">
<tr>
<td colspan="2" align="center"><font color="#400040"><b>Register No</b></font></td>
<th colspan="2"><font color="Brown">42209104069</font></th>
<td colspan="2" align="center"><font color="#400040"><b>Name</b></font></td>
<th colspan="2"><font color="Brown">SATHISH KUMAR R</font></th>
</tr>
<tr>
<td colspan="2"><font color="blue"><center><b>Subject</b></font></td>
<td colspan="2"><font color="blue"><center><b>Credits</b></font></td>
<td colspan="2"><font color="blue"><center><b>Grade</b></font></td>
<td colspan="2"><font color="blue"><center><b>Result</b></font></td>
</tr>
<tr>
<td colspan="2" class="a"><center> CS2301</td> //1
<td colspan="2" class="a"><center> 3</td> //2
<td colspan="2" class="a"><center> E</td> //3
<td colspan="2" class="a"><center> PASS</td> //4
</tr>
</table>";
var paser = new HtmlParser();
var node = paser.Pasrse(html);
var finder = new FindTagsVisitor(TagBuilder => tag.Name == "td" && tag.Attributes.ContainsKey("class"));
node.AcceptVisitor(finder);

Categories

Resources