Using a C# variable as a table element - c#

What I have is this:
<table>
<tr bgcolor="#007ACC" style="color:White">
<td width="145">Account Group</td>
<td width="80"></td>
<td width="10">Active</td>
</tr>
<tr>
·
·
</tr>
</table>
What I need to do is make it so "Account Group" can be changed based on a user's treeview selection. i.e., if the user selects a Child node, I need to change that to "Account Number".
Is it possible to change a table element on-the-fly like that? If so, how would I do this?

Place a label in <td> to display text, so that you can change them based on label id
<td width="145">
<asp:Label Text="Account Group" ID="lblUserContent" runat="server" />
</td>
As per treeview selection changes you can change the text by using following code:
if(your condition)
lblUserContent.Text="Account Number"
else
lblUserContent.Text="Account Group"

The best way to do this will depend on how you're using your treeview, but here's a quick way to output the value of a C# variable into your table:
<table>
<tr bgcolor="#007ACC" style="color:White">
<td width="145"><%# Eval("MyCSharpVariable") %></td>
<td width="80"></td>
<td width="10">Active</td>
</tr>
<tr>
·
·
</tr>
</table>

Related

Why do my rows in a colums suddenly jump to the right? And how do I fix that?

Good Day everyone. So while trying to add a few date fields to a popup window on a site I am making I experienced something odd. Adding these 3 rows to the pop up caused the column they were suppose to be in to jump to the right and now i can not get them to line up.
I do not know how important it is to note, but there is a textbox to the left of the column, but the boxes/rows i am adding will be below the textbox's height.
Below I have tried to take a slice of the code as an example, if it is enough I will attempt to add more:
<table style="float: left;">
<tr>
<div>
<tr>(the following code shows normally like it should)
<td align="left" valign="top" colspan="4">Lable:</td>
</tr>
<tr>
<td width="2px"></td>
<td align="left" valign="top">Label</td>
<td colspan="3">
<telerik:RadDatePicker ID="RDP1" runat="server"
Culture="Language"
DbSelectedDate='<%# (Container is GridEditFormInsertItem)? DateTime.Today : Eval("EVAL1") %>'
Width="145px">
<Calendar ID="Calendar3" runat="server" UseColumnHeadersAsSelectors="False" UseRowHeadersAsSelectors="False" ViewSelectorText="x">
</Calendar>
<DatePopupButton HoverImageUrl="" ImageUrl="" />
<DateInput ID="DateInput3" runat="server" DateFormat="dd-MM-yyyy" DisplayDateFormat="dd-MM-yyyy">
</DateInput>
</telerik:RadDatePicker>
</td>
</tr>
<tr>
<td></td>
<td colspan="3">Label</td>
</tr>
<tr>
<td></td>
<td align="left" valign="top">Label:</td>
<td align="left" valign="top" colspan="3">
<telerik:RadDatePicker ID="RDP2" runat="server" Culture="Language" DbSelectedDate='<%# Eval("EVAL2") %>' Width="170px">
<Calendar ID="Calendar5" runat="server" UseColumnHeadersAsSelectors="False" UseRowHeadersAsSelectors="False" ViewSelectorText="x">
</Calendar>
<DateInput ID="DateInput5" runat="server" DateFormat="dd-MM-yyyy" DisplayDateFormat="dd-MM-yyyy">
</DateInput>
</telerik:RadDatePicker>
<asp:ImageButton ID="btnDelete" runat="server" ImageUrl="url" OnClick="btnFunction_Click" ToolTip="Text" Style="vertical-align:middle;" />
</td>
</tr>
</div>
</tr>
For those that would like to see the CSS, there is none, at least none that would have an impact on my problem as they are pointing more towards the actual webpage and not the pop up window.
In advance I would like to say Thank you for the help and your time.
The problem occurs because your rows don't have an equal number of <td> or columns
First row - 1 td with colspan 4 > total 4
Second row - 1 td + 1 td + 1 td with colspan 3 > total 5
Third row - 1 td + 1 td with colspan 3 > total 4
Fourth row - 1 td + 1 td + 1 td with colspan 3 > total 5
Your table is not in the correct structure (you have a tr in a td)
Ensure your table is in the following structure:
<table>
<tr>
<td>
Also check your columns are all equal, use colspan="" to merge cells if needed.
<table>
<tr>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<td colspan="4"></td>
</tr>
<table>

XPath drops contents of td column on an HTML page for screen scraping

Below you find an excerpt of code used to screen scrape an economic calendar.
The HTML page that it parses using XPath includes this row as the first rown
in a table. (Only pasted this row instead of the entire HTML page.)
<tr class="calendar_row newday singleevent" data-eventid="42064"> <td class="date"><div class="date">Sun<div>Dec 23</div></div></td> <td class="time">All Day</td> <td class="currency">JPY</td> <td class="impact"> <div title="Non-Economic" class="holiday"></div> </td> <td class="event"><div>Bank Holiday</div></td> <td class="detail"><a class="calendar_detail level1" data-level="1"></a></td> <td class="actual"> </td> <td class="forecast"></td> <td class="previous"></td> <td class="graph"></td> </tr>
This code that selects the first tr row using XPath:
var doc = new HtmlDocument();
doc.Load(new StringReader(html));
var rows = doc.DocumentNode.SelectNodes("//tr[#class=\"calendar_row\"]");
var rowHtml = rows[0].InnerHtml;
The problem is that rowHtml returns this:
<td class="date"></td> <td class="time">All Day</td> <td class="currency">EUR</td> <td class="impact"> <div title="Non-Economic" class="holiday"></div> </td> <td class="event"> <div>French Bank Holiday</div> </td> <td class="detail"><a class="calendar_detail level2" data-level="2"></a></td> <td class="actual"> </td> <td class="forecast"></td> <td class="previous"></td> <td class="graph"></td>
Now you can see that the contents of the td column for the date vanished! Why?
I've experimented many things and stumped as to why it drops the contents of that column.
The other columns have content that it keeps. So what's wrong with the date column?
Is there some kind of setting or property somewhere to cause or prevent dropping contents?
Even if you haven't got a clue what's wrong but have some suggestions of a way to investigate it more.
Like #AlexeiLevenkov mentioned, you must be selecting a different row than what you want. You've pruned too much of essential problem away in an effort to simplify, but it's still clear what's wrong...
Consider that your input document might basically look like this:
<?xml version="1.0" encoding="UTF-8"?>
<table>
<tr class="calendar_row" data-eventid="12345">
<td>This IS NOT the tr you're looking for</td>
</tr>
<tr class="calendar_row newday singleevent" data-eventid="42064">
<td>This IS the tr you're looking for</td>
</tr>
</table>
The test #class="calendar_row" won't match against the tr you show, but it will match against the first row.
You could change your test to be contains(#class,'calendar_row') instead, but that would match both rows. You're going to have to identify some content or attribute that's unique to the row you desire. Perhaps the #data-eventid attribute would work -- can't tell without seeing your whole input file.

How to get Dynamic Span id in jquery?

Iam using jquery in asp.net
I have one user control in which i have div and in div table and in table tr and in tr td and in td i have lables.
ASCX :
<div ID="Container" runat="server" class="dvContainer">
<table ID="Table" class = "Tablecs">
<thead><tr>
<td colspan="2">
<asp:Label ID="lbl1" Text="Swiss" runat="server" /></td>
</tr>
</thead>
<tr>
<td>ABC</td>
<td>DEF</td>
</tr>
<tr>
<td><asp:Label ID="lblPA" Text="SUN 12/21 05:04" runat="server" /></td>
<td ><asp:Label ID="lblPD" Text="SUN 12/21 19:00" runat="server" /></td>
</tr>
<tr>
<td><asp:Label ID="lblAA" Text="SUN 12/21 05:04" runat="server" /></td>
<td ><asp:Label ID="lblAD" Text="SUN 12/21 19:00" runat="server" /></td>
</tr>
</table>
i want to bind data dynamically to these user control. i.e., binding data to lables in user contol.
my Jquery
$div.find(".Table").text(oPorts[iCount].Name); // my result is an array of oPorts and i have filed as Name
But this is not working fine.
when i checked into code dynamically its generating SPAN for each and every lable
How to find that SPAN id dynamiccaly in a loop and bind data to lables??
Any help is appreciated. Thanks in Advance.
suppose you have a usercontrol with a markup like given below
<%# Control Language="C#" AutoEventWireup="true"
CodeBehind="WebUserControl1.ascx.cs" Inherits="DOTNET_FORMS.WebUserControl1" %>
<div id="Container" runat="server" class="dvContainer">
<table id="Table" class="Tablecs">
<tr>
<td>
<asp:Label ID="lblPA" Text="SUN 12/21 05:04" runat="server" />
</td>
<td>
<asp:Label ID="lblPD" Text="SUN 12/21 19:00" runat="server" />
</td>
</tr>
</table>
</div>
and you have registered this usercontrol on your .aspx page like this:
<%# Register TagPrefix="UC" TagName="Test" Src="~/WebUserControl1.ascx" %>
and used it like this:
<UC:Test ID="uc1" runat="server" />
then, when you run your page, your elements get rendered something like
<div id="uc1_Container" class="dvContainer">
<table id="Table" class="Tablecs">
<tr>
<td>
<span id="uc1_lblPA">SUN 12/21 05:04</span>
</td>
<td>
<span id="uc1_lblPD">SUN 12/21 19:00</span>
</td>
</tr>
<tr>
<td>
<span id="uc1_lblAA">SUN 12/21 05:04</span>
</td>
<td>
<span id="uc1_lblAD">SUN 12/21 19:00</span>
</td>
</tr>
</table>
</div>
see how ids of your labels and other elements (elements with runat="server" attribute ) got changed i.e.
lblPA > uc1_lblPA
lblPD > uc1_lblPD
Container > uc1_Container
so, you have to look out for these changes, because only then you can grab these elements using jQuery, cause jQuery is a client side language, it executes, after the server side code (runat="server") has executed.
However, if you do not want to look out for modified id, you can do following
remove runat="server" attribute, and make sure your ids are unique, all of them
let the runat="server" attribute be their, place an attribute clientidmode="static" on all of your server side controls. and Ids wont change.
use ClientId i.e. in your jQuery selector, grab an element like this: $('#"+'<%= lblPA.ClientID %>');
now, since your IDs are unique, you don't need to find, directly grab the elements like this:
$('#lblPA').text();
or if you want to loop through all the tds of your table with class Tablecs, do this:
$('.Tablecs tr td').each(function(index, item){
alert($(item).text());
});

How do I create an email template within my application [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Razor views as email templates
I am sending out an email to the user from within my service of my website.
I want to format this so that it shows nice and a specific way.
Here is what I have:
<table bgcolor="#FFE680" border="0" cellpadding="0" cellspacing="0" width="100%">
<tbody>
<tr>
<td width="100%" height="51" valign="middle"><h1> <strong>[COMPANY] User ID Reminder </strong></h1></td>
<td align="right" valign="top" width="8"><img alt="" width="8" height="8" align="top" /></td>
</tr>
</tbody>
</table>
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tbody>
<tr>
<td><table border="0" cellpadding="0" cellspacing="0" width="100%">
<tbody>
<tr>
<td align="left" valign="top" width="100%"><table border="0" cellpadding="0" cellspacing="0" width="100%">
<tbody>
<tr>
<td><table border="0" cellpadding="0" cellspacing="0" width="100%">
<tbody>
<tr>
<td colspan="1" align="left"></td>
</tr>
<tr>
<td align="left" valign="top" width="100%"><p> <br />
Dear [USERNAME], </p>
<p> In response to your request to be reminded of your User ID, please find below the information we have on file for you. If you didn't submit this request, ignore this email. </p>
<table border="0" cellpadding="0" cellspacing="0">
<tbody>
<tr>
<td>Your User ID is: </td>
<td>[USERNAME]</td>
</tr>
<tr>
<td>Your registered email address is:  </td>
<td>[EMAIL]</td>
</tr>
</tbody>
</table>
<p>
If you have forgotten your password, you can request it here.<br />
</p>
<p>
Thank you,<br />[COMPANY]
</p></td>
</tr>
</tbody>
</table></td>
</tr>
</tbody>
</table></td>
</tr>
</tbody>
</table></td>
</tr>
</tbody>
</table>
Now my question isn't about the looks of the email but how do I put this as the body of my email while populating the appropriate fields?
I put it in resources as a string and I figured I'd just do a replace of the specific [fields]. This starting becoming tedious and seemed sloppy:
var body = SuburbanHUB.Properties.Resources.ForgotPasswordEmailBody.Replace("[USERNAME]", username).Replace("[EMAIL]")...
I'm sure there is a better way of doing this but I have not the experience.
=== CLARIFICATION ===
I am using razor to call a WCF service written in C#. The service that is being called is where the email is being sent from and not the view. I am using Razor with MVC with C# as the underlying code.
I'm in the middle of trying to do the same thing. We're using Razor templates to generate the email, and passing in a Model which has all the various variables to fill it out. This lets us include everything that Razor and MVC support, including #if and #Html.Partial, which lets us construct an email from pieces.
The answer we just went with involves running an internal MVC webserver, requesting pages from it with the Model as a parameter, and capturing the response text, but there's variants on my question that are more self contained. Take a look and see if any of the other answers or comments help you.
I had similar requirement and I end up using NVelocity and it worked great for me. Please see this article for a workthrough http://www.codeproject.com/Articles/12751/Template-merging-with-NVelocity-and-ASP-NET. You have to modify your fields in the template according to the velocity templating language. Download NVelocity from http://nvelocity.sourceforge.net/.

Insert data into asp.net table through code

I have a table in asp.net page and i want to insert the data which will be recieved from service call through c# code behind. Any idea on how to do this.
Below is my table.
<table id="DataTable" class="style1">
<tr>
<td>
</td>
<td>
</td>
<td>
</td>
<td>
</td>
</tr>
</table>
I just need to insert values recieved from service call in place of &nbsp.
In your aspx page asp:Label controls and assign the values from code behind by accessing them using Id.
Inside .aspx
<asp:Label Id="lblName" runat="server">
In code behind
lblName.Text = "Value from Service";
If you need to repeat this table use GridView.
Use the asp:Table control instead.. It gives you much more control from server side than a normal html tag :)
And it ofc render as a normal table client side
If you persist on working with pure html table you can use an new/old style to control it.
like so:
<table>
<% foreach ( var o in objects ) { %>
<!--UserControl -->
<tr>
<td> can put here data like so: <%= o.Id %> </td>
</tr>
<!--UserControl -->
<%}%>
</table>
or you can use Repeater and Bind data if it's dynamic.
If data is not dynamic and your table will not grow or change size, you can use a little OOP for this.
like so:
create in your class properties and then populate them.
public string MyLabel { get; set; }
put something in page load.
in aspx do it like so..
<table>
<tr>
<td> <%= MyLabel %> </td>
</tr>
</table>
or
<table>
<tr>
<td> <asp:Label ID=|"myText" runat="server"/> </td>
</tr>
</table>
Make the table Html server side control. Try this:
<table runat="server" id="DataTable" class="style1">
<tr>
<td id="td1" runat="server">
</td>
<td id="td2" runat="server">
</td>
<td id="td3" runat="server">
</td>
<td id="td4" runat="server">
</td>
</tr>
Now in the code behind
td1.InnerText="xx" or td1.InnerHtml=..

Categories

Resources