I have a following code:
DataSourceSelectArguments sr = new DataSourceSelectArguments();
DataView dv = DurationSQL.Select(sr) as DataView;
if (dv.Count != 0)
{
GridView2.Rows[0].Cells[0].Text = "Duration: \r" + dv[0][0].ToString() + "\r|";
}
I would like to make the static text:
Duration:
Displayed in bold while the rest of the text has no styling applied any way to achieve this?
You can put HTML into the cell text to achieve this, while at the same time preventing that HTML from being HtmlEncoded, like this:
Put HTML into the cell:
GridView2.Rows[0].Cells[0].Text = "<b>Duration:</b><br />"
+ HttpUtility.HtmlEncode(dv[0][0].ToString()) + "<br />|";
I included a call to .HtmlEncode(), but if the value is e.g. a number you may even skip that.
Prevent HTML from being encoded (use it for your first column, based on the fact that you use Cells[0]):
<asp:BoundField DataField="YourColumn" HtmlEncode="False" />
string text = GridView1.Rows[0].Cells[0].Text;
var span1 = new HtmlGenericControl("span");
span1.InnerHtml = "<strong>Duration:</strong> \r" + text;
GridView2.Rows[0].Cells[0].Text = span1.InnerHtml;
Seemed to work thanks for the comment
Related
We're trying to populate a Calendar for our Installation Team that shows distinct values from a query of Van Number and Install Time on each date in the calendar. We have it so there's a clickable Date in each cell that does something, and below that a Text String shows up with the Van # and Time. However this is duplicating.
We thought it was the String, but if we make build the same string and write it to the ToolTip for that Cell, it displays correctly. So it's that cell text for some reason.
Here's the relevant code:
protected void Calendar1_DayRender(object sender, DayRenderEventArgs e)
{
String Install = "";
String ToolTip = "";
Literal insta = new Literal();
Literal lit = new Literal();
e.Cell.BackColor = System.Drawing.Color.SkyBlue;
var rows = (from row in socialEvents.AsEnumerable()
where DateTime.Parse(row["InstallDate"].ToString()) >= e.Day.Date &&
DateTime.Parse(row["InstallDate"].ToString()) < e.Day.Date.AddDays(1)
select new
{
VanNum = row["VanNum"],
InstallTime = row["InstallTime"]
}).Distinct();
foreach (var row in rows)
{
String MyInstall = "";
MyInstall = "Van #: " + row.VanNum.ToString() + " / Install Time: " + row.InstallTime.ToString();
Install = Install + "<br/>" + MyInstall;
ToolTip = ToolTip + "/n" + MyInstall;
}
e.Cell.ToolTip = ToolTip;
lit.Visible = true;
e.Cell.Controls.Add(lit);
insta.Text = Install;
insta.Visible = true;
e.Cell.Controls.Add(insta);
}
e.Cell.ToolTip will display 3 rows, but the Literal insta.Text in the Cell Control will show it twice. The Literal lit seems to be adding the clickable Date (which I admit, I don't know how its doing that) which is why there's two Literal Controls. If we just write a single Literal Control then we lose the clickable Date but the Install data is still duplicated.
After testing more we found that the Control with text was being added twice. Not sure why we didn't see the date twice as well. But we found the answer here:
https://forums.asp.net/t/453021.aspx?My+DayRender+event+is+happening+twice+and+I+don+t+know+why+
The DayRender event was firing twice, so removing
OnDayRender="Calendar1_DayRender"
from the ascx page removed the redundant firing and text only displayed once. I'm still unsure why the Date gets added to lit and only once, but that seems to be generated elsewhere and probably accounted for. This also explains the ToolTip working, because its getting set where the Control is being added.
i want to display the text in rows how can i do this here is the code which does that
text=messages+"";
Please change this line of code:
szText = szText + szMessage + "\r<br>";
To this:
szText += szMessage;
well, I've been trying to create a new custom property in a shape and I somehow managed, however, when I try to change the name of the Label I can only write numbers. Could you provide me how to do it in C# or maybe in VB so I can get a hint?
My code is:
//First I create the row
shape.AddRow((short)VisSectionIndices.visSectionProp,(short) (iRow + 1), (short) VisRowTags.visTagDefault);
//And now I try to write the Label
shape.CellsSRC[(short)VisSectionIndices.visSectionProp, (short)(iRow + 1), (short)VisCellIndices.visCustPropsLabel].Result[VisUnitCodes.visNoCast] = 123456789
However, when the Result method only accepts boolean as input, and I don't know how to write a string overthere...
Thanks in advance!
I've also been looking into how to set the string value of a custom shape data property.
Just got it to work like this:
var newPropertyValue = "cool new value";
tstShape.Cells["Prop.SuperCustomPropertyName"].FormulaU = "\"" + newPropertyValue + "\"";
Disclaimer that I am no expert with Visio Automation, but it works in my circumstance.
I'm using visio 2010 and studio 2010
Hopefully it helps.
You can use the following code:
private void AddCustomProperty(Microsoft.Office.Interop.Visio.Shape shape, string PropertyName, String propertyValue)
{
try
{
short customProps = (short)VisSectionIndices.visSectionProp;
short rowNumber = shape.AddRow(customProps, (short)VisRowIndices.visRowLast, (short)VisRowTags.visTagDefault);
shape.CellsSRC[customProps, rowNumber, (short)VisCellIndices.visCustPropsLabel].FormulaU = "\"" + PropertyName + "\"";
shape.CellsSRC[customProps, rowNumber, (short)VisCellIndices.visCustPropsValue].FormulaU = "\"" + propertyValue + "\"";
}
catch (Exception e)
{
System.Windows.Forms.MessageBox.Show("Error: " + e.Message);
}
}
The Result isn't meant to be read/write. What you want to do is set the FormulaU property of the cell to the label name. The Result property just calculates the formula for the cell and returns the result, which is why you have to provide a unit for the return value.
Also, the AddRow method returns the actual row number for the added row, which isn't necessarily the row you specified. For shapesheet sections with nameable rows, like the Custom Properties section, Visio may ignore the row you requested and just stick it at the bottom.
I am trying to use a multiline textbox to insert text into a table which is displayed as html. I want to with javascript take the text inside of the textbox and find where the user pressed enter and place "<br/>" in that position so when the text is displayed it will show line break. Any ideas on how I could do this?
I tried something like this but it did not work.
var text = document.getElementById("announcementid").value;
var newtext = text.replace("\n", "<br/>");
text = newtext;
The newtext variable ends up being a copy of the original string from your announcementid element. Thus, you'll need to re-set the value property on the original document element:
var text = document.getElementById("announcementid").value;
var newtext = text.replace(/\n/g, "<br />");
document.getElementById("announcementid").value = newtext;
Also, as Konstantin pointed out, the replace() function in Javascript will just replace the first instance unless you pass in a global regular expression.
Fiddle example
Text is a primitive so it would not replace the value. Use a regular expression to globally replace instead of replacing just the first instance:
var text = document.getElementById("announcementid").value;
var newtext = text.replace(/\n/g, "<br />");
document.getElementById("announcementid").value = newtext;
I need to create a pdf from .aspx page. In .aspx page user will enter so many values in textbox and gridview. It also has some tabs with different sections. I did used iTextSharp for creating simple pdf. But here i need to get the values from the page and need to read the tab controls. So is it posible to use iTextSharp or is there any opensource dll available for converting .aspx to pdf..
Give me some idea?
Thanks..
By using ITextsharp library,this can be done by using HTMLWorker :
First Create String builder;
private StringBuilder sb;
Then add pdf heading from textbox value as:
sb.Append("<p style=\"text-align: center;font-size:" + fontSize + "px;font-weight:" + (bold ? "bold" : "normal") + ";\">" + txtHeading + "</p>");
Then add subject to pdf from textbox value as:
sb.Append("<table><tr valign=\"top\"><td>Subj:</td><td style=\"font-size:" + fontSize + "px;font-weight:bold;text-decoration:underline;\">" + txtSubject.text + "</td></tr></table><br />");
Then add paragraphs from textbox value as:
sb.Append("<p style=\"text-align: left;font-size:" + fontSize + "px;font-weight:" + (bold ? "bold" : "normal") + ";\">" + txtParagraph + "</p><br/>");
for table creation take values in string[] array
sb.Append("<table width=\"100%\" cellspacing=\"0\" cellpadding=\"3\" border=\"0.5\"><thead><tr align=\"center\" valign=\"top\">");
foreach (string str in StringArray)
{
sb.Append("<th><strong>" + str + "</strong></th>");
}
sb.Append("</tr></thead>");
And so on.You can create pdf from textbox values of aspx page.
Itext Sharp quite easy .about tabs ,I dont know may be it will work ,as it works for paging ,I mean it converts all the matter in the paging ,in a single pdf
Click Here For Example