I have textbox and a button on my aspx page.
Now I want to create a html table as string on button click event. I have done this task. Please look at my below code:
string stsrtest = "test";
string nWidth="150px";
string strHtml = "<table><tr><td width= '" + nWidth + "'> Authorized By</td><td>Employee </td><td>Status</td><td>Date </td><td>Note</td><td>Signutare</td></tr>";
strHtml += "<tr><td> " + stsrtest + "</td><td> " + stsrtest + "</td><td> " + stsrtest + "</td><td> " + stsrtest + "</td><td> " + stsrtest + "</td><td>test</td></tr>";
strHtml += "</table>";
Now I want to create row and column dyanically based on textbox value.
For Example if textbox value is 15 then I want create a table with 3 column and 5 Rows.
and if textbox value is 6 then I want create a table with 3 column and 2 Rows.
I have use above code to create a simple 2 rows and 5 column.
I have solved this issue using below code:
int nTotal = Convert.ToInt32(txtCell.Text);
int nRows = 0;
int nLast = nTotal % 3;
nRows = nTotal / 3;
string strHmtl = "<table border='1px' cellspacing='0' cellpadding='0' style='height: 28px; width: 647px;' >";
for (int i = 0; i < nTotal - nTotal % 3; i++)
{
if (i == 0 || i % 3 == 0)
strHmtl += "<tr>";
strHmtl += "<td></td>";
if (i % 3 == 2)
strHmtl += "</tr>";
}
if (nTotal % 3 != 0)
{
strHmtl += "<tr>";
if (nLast == 1)
strHmtl += "<td> </td>";
else
{
strHmtl += "<td> </td>";
strHmtl += "<td> </td>";
}
strHmtl += "</tr>";
}
strHmtl += "</table>";
Thanks.
You can just build your table dynamically by setting the number of your columns and looping for each row to build it as string. Take a look at this example:
StringBuilder l_strBuilder= new StringBuilder();
l_strBuilder.AppendLine("<table">");
l_strBuilder.AppendLine("<tr>");
l_strBuilder.AppendLine("<th>Authorized By</th>");
l_strBuilder.AppendLine("<th>Employee</th>");
l_strBuilder.AppendLine("<th>Status</th>");
l_strBuilder.AppendLine("<th>Date</th>");
l_strBuilder.AppendLine("<th>Note</th>");
l_strBuilder.AppendLine("<th>Signutare</th>");
l_strBuilder.AppendLine("</tr>");
for (int i = 0; i < ROWSNUMBER; i++)
{
l_strBuilder.AppendLine("<tr>");
l_strBuilder.AppendLine("<td>column 1 data</td>");
l_strBuilder.AppendLine("<td>column 2 data</td>");
l_strBuilder.AppendLine("<td>column 3 data</td>");
l_strBuilder.AppendLine("<td>column 4 data</td>");
l_strBuilder.AppendLine("<td>column 5 data</td>");
l_strBuilder.AppendLine("<td>column 6 data</td>");
l_strBuilder.AppendLine("</tr>");
}
l_strBuilder.AppendLine("</table>");
After the building the table you can use the asp literal obj to put your table in your page.
<asp:Literal ID="ltrDynTable" runat="server" />
And fill it with your string this way:
ltrDynTable.Text = l_strBuilder.ToString();
Hope it will help.
Related
I am needing to be able to generate columns and values from dynamic data. My model is a List that contains a string and another list. The string is the column name, which I can get to display correctly. The list however I have not been able to get working correctly. I am getting one of three things all the time. 1) No values 2) The control name 3) The values but the values for each Column level item.
So with 3 columns and each column having 3 data point I can generate all three columns, but I get all three columns worth of data in each column.
Below is the code I am using for the data grid it's self as well as the code for adding the data to the outer and inner lists.
If anyone has any ideas of how to complete this I could really use the help at this point.
public List<rdzTest> getData()
{
for(int i = 0; i<5; i++)
{
rdzTest rt = new rdzTest();
//rt.name = new List<string>();
rt.name = "Property Name " + " -- " + i.ToString();
rt.values = new List<string>();
string s = "";// "<ul>";
for (int j = 0; j < 10; j++)
{
//s += "<li>values " + j.ToString() + " Property -- " + i.ToString() + "</li>";
s = "values " + j.ToString() + " Property -- " + i.ToString();
rt.values.Add(s);
}
//s += "</ul>";
//rt.values = s;
alpha.Add(rt);
//alpha.name = rt.name;
//alpha.values = rt.values;
}
return alpha;
}
<RadzenDataGrid TItem="rdzTest" Col Data=#alpha>
<Columns>
#foreach(rdzTest rt in alpha)
{
<RadzenDataGridColumn TItem="rdzTest" Property=#rt.name Title="#rt.name">
<Template>
<ul>
#foreach(string st in rt.values)
{
<li>
#st
</li>
}
</ul>
</Template>
</RadzenDataGridColumn>
}
</Columns>
</RadzenDataGrid>
i have a scenario where there is an LOV with High Value as "Package" and TYPE="TO_NEW_PACKAGE" and i have to fetch the value of Low and there are 8 records in Low. I Have to display all the 8 records and their component cost for each record. All this should be gone as a display Message which will be output. Please let me know how to do this.
var sSearchExp = "[Type]= '" + "PACKAGE_PLAN" + "' AND [High] = '" + PACKAGEPLAN + "'"; SetSearchExpr(sSearchExp); ExecuteQuery(); var isRecord = FirstRecord(); while(isRecord) { Slow = GetFieldValue("Low"); Outputs.SetProperty ("NEW_PACKAGE_PLAN",Slow); Outputs.SetProperty("ErrorCode", "00"); Outputs.SetProperty("ErrorDesc", "Success"); i = i+1; isRecord = NextRecord(); }
this is storing only 1 record... i want all the eight records to be displayed!
This should get you started
var sSearchExp = "[Type]= '" + "PACKAGE_PLAN" + "' AND [High] = '" + PACKAGEPLAN + "'";
var Slow = "";
SetSearchExpr(sSearchExp);
ExecuteQuery();
var isRecord = FirstRecord();
while (isRecord) {
Slow += GetFieldValue("Low");
Slow += " ";
i = i + 1;
isRecord = NextRecord();
}
Outputs.SetProperty("NEW_PACKAGE_PLAN", Slow);
Outputs.SetProperty("ErrorCode", "00");
Outputs.SetProperty("ErrorDesc", "Success");
This sample code will print the values downwards:
var boAsset = TheApplication().GetBusObject("List Of Values");
var bcAsset = boAsset.GetBusComp("List Of Values");
with (bcAsset)
{
ActivateField("Value");
var sSearchExp = "[Type]= 'AAG_TABLE_TYPE'";
var Slow = "";
SetSearchExpr(sSearchExp);
ExecuteQuery();
var isRecord = FirstRecord();
while (isRecord)
{
Slow += GetFieldValue("Value");
Slow += "\n";
isRecord = NextRecord();
}
TheApplication().RaiseErrorText(Slow);
}
Output:
AAG Account
AAG Holdg
AAG Portf
AAG Txn
Changing Slow += "\n"; to Slow += " "; will print the values sideways.
Hope you get the trick here.
I am trying to loop through a csv file pushing each column into an array but I am not sure how to do that, I know that the tag {{!COL1}} will give me the data I want but I can't figure out how to save it into a variable I can use to push inside an array.
csvToArray = "CODE:";
csvToArray += "SET !DATASOURCE artist.csv" + "\n";
csvToArray += "SET !ERRORIGNORE YES" + "\n";
csvToArray += "SET !DATASOURCE_LINE {{CSV}}" + "\n";
csvToArray += "SET !VAR1 {{!COL1}}" + "\n";
for(i = 0; i < 10; i++){
iimSet("CSV", i);
iimPlay(csvToArray);
}
This code will allow me to loop through a csv file, and the {{!COL1}} tag gives me the data i want, how do i save this into a varialbe i can use, please someone help cant figure this one out. :(
To get the data of COL1 you will need to set EXTRACT = COL1, then assign your variable to iimGetLastExtract().
Add this to your macro:
csvToArray += "SET !EXTRACT {{!COL1}}";
Then add this to your js file:
var myArray = []; // place at top of file for readability
myArray.push(iimGetLastExtract()); // place at end of for loop
// puts each extraction into myArray
Try the below code block.
function read_file(path) {
var content = '', i = 1, f, res = '',spl;
while (1){
content = res;
if (content != "") {
spl = content.split("|");
//spl[0] will contain the Row1 and Column1 value, spl[1] will contain Row 1 and Column 2 value etc.,
/*Here you can specify your script/conditions
Example:
iimPlay('CODE:TAG POS=1 TYPE=INPUT:TEXT ATTR=NAME:login[username] CONTENT='+spl[0]);
iimPlay('CODE:TAG POS=1 TYPE=INPUT:PASSWORD ATTR=NAME:login[password] CONTENT='+spl[1]);
I used the infinite loop, so in order to come out of the loop, you need to add a condition like below
if (spl[0]=="End") {//In your input sheet if the Row1,Col1 contains the value 'End', then it will exit the loop
iimDisplay("All Rows Completed");
return;
}
*/
f = "CODE: "+"\n";
f += "SET !EXTRACT null" + "\n";
f += "SET !LOOP 3" + "\n";
f += "SET !DATASOURCE \""+path+"\" "+"\n";
f += "SET !DATASOURCE_COLUMNS 5" + "\n"; //Assume that you have five columns in the your input file
f += "SET !DATASOURCE_LINE " + i + "\n";
f += "SET !EXTRACT {{!col1}}|{{!col2}}|{{!col3}}|{{!col4}}|{{!col5}}" + "\n";
iimPlay(f);
res = iimGetLastExtract();
i++;
}
return content;
}
var file_conten = read_file("yourinputfilename.csv");
Code What I tried:
private void ExporttoExcel(DataTable table)
{
filename = "All_OS" + "_" + datepicker.Value.Replace("/", "-").ToString() +".xls";
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.ClearContent();
HttpContext.Current.Response.ClearHeaders();
HttpContext.Current.Response.Buffer = true;
HttpContext.Current.Response.ContentType = "application/vnd.ms-excel";
HttpContext.Current.Response.Write(#"<!DOCTYPE HTML PUBLIC ""-//W3C//DTD HTML 4.0 Transitional//EN"">");
HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment;filename=" + filename);
HttpContext.Current.Response.Charset = "utf-8";
HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.GetEncoding("windows-1250");
HttpContext.Current.Response.Write("<style> .amt{mso-number-format:\"\\#\\#0\\.00\";} </style>"); //sets font
HttpContext.Current.Response.Write("<font style='font-size:10.0pt; font-family:Calibri;'>");
HttpContext.Current.Response.Write("<BR><BR><BR>");
//sets the table border, cell spacing, border color, font of the text, background, foreground, font height
HttpContext.Current.Response.Write("<Table border='1' bgColor='#ffffff' "
+ "borderColor='#000000' cellSpacing='0' cellPadding='0' "
+ "style='font-size:10.0pt; font-family:Calibri; background:white;'> <TR>");
//am getting my grid's column headers
int columnscount = table.Columns.Count;
HttpContext.Current.Response.Write("<TR>");
HttpContext.Current.Response.Write("<Td colspan=23>");
HttpContext.Current.Response.Write("<font style='font-size:12.0pt; font-family:Calibri;'><CENTER> ");
HttpContext.Current.Response.Write("All Outstanding " + datepicker.Value.ToString());
HttpContext.Current.Response.Write(" </CENTER></Font> ");
HttpContext.Current.Response.Write("</Td>");
HttpContext.Current.Response.Write("<TR>");
for (int j = 0; j < columnscount; j++)
{
//write in new column
HttpContext.Current.Response.Write("<Td>");
//Get column headers and make it as bold in excel columns
HttpContext.Current.Response.Write("");
HttpContext.Current.Response.Write(table.Columns[j].ColumnName.ToString());
HttpContext.Current.Response.Write("");
HttpContext.Current.Response.Write("</Td>");
}
HttpContext.Current.Response.Write("</TR>");
foreach (DataRow row in table.Rows)
{//write in new row
HttpContext.Current.Response.Write("<TR>");
for (int i = 0; i < table.Columns.Count; i++)
{
HttpContext.Current.Response.Write("<Td>");
HttpContext.Current.Response.Write(row[i].ToString());
HttpContext.Current.Response.Write("</Td>");
}
HttpContext.Current.Response.Write("</TR>");
}
HttpContext.Current.Response.Write("</Table>");
HttpContext.Current.Response.Write("</font>");
HttpContext.Current.Response.Flush();
HttpContext.Current.Response.End();
}
Output
Actual Result
50
100
2,100.00
3,450.00
Expected Result
50.00
100.00
2,100.00
3,450.00
Try like this:
You can Use simply round the value in output:
String.Format("{0:0.00}", 123.45678);
in Your Context:
String.Format("{0:0.00}", row[i].ToString());
Here is XML received by any web service,
<diy>
<tag1>14</tag1>
<tag2>2.000000000000000e+000</tag2>
<tag3>2.800000000000000e+001</tag3>
</diy>
This is code:
IEnumerable<XElement> xTag = from p in xmlDoc.Elements("document").Elements("xServ").Elements("b")
select p;
string tab = "<Table>";
foreach (var xTags in xTag)
{
tab += "<tr><td>" + Convert.ToString(xTags.Element("r").Element("Exp").Value) + "</td>";
tab += "<td>" + Convert.ToString(xTags.Element("r").Element("diy").Element("tag1").Value) + "</td>";
string s = Convert.ToString(xTags.Element("r").Element("diy").Element("tag2").Value);
string d = Math.Round(Convert.ToDouble(s)).ToString();
tab += "<td>" + d + "</td>";
tab += "<td>" + Convert.ToString(xTags.Element("r").Element("diy").Element("tag3").Value) + "</td>";
tab += "</tr>";
}
divTag.InnerHtml = tab + "</Table>";
When I used Math.Round(), it gives me "2,8E+16" !
how can I convert "2.000000000000000e+000" to "2" and "2.800000000000000e+001" to "28" in ASP.NET ?
Use Math library:
Math.Round(Convert.ToDouble("2.800000000000000e+001")).ToString();
that will return "28" .
How about this:
decimal.Parse("2.800000000000000e+001", System.Globalization.NumberStyles.Float).ToString("0.#");
Edit: added .NET format string to reduce to "28"
public static int function(float tag2)
{
do
{
if(tag2%10==0)
{
tag2=tag2/10.0;
}
else
{
int res = tag2;
return res;
}
}
while(true)
}
well I have to say that my solution is a bit funny! and beside that uses more memory than other ways.although other solutions use more cpu! life is trade off!
string MyNumber = "2.8000000e+1";
int DotIndex = MyNumber.IndexOf('.');
MyNumber = MyNumber.Remove(DotIndex, 1);
if(MyNumber[DotIndex] != '0')
DotIndex++;
MyNumber = MyNumber.Remove(DotIndex, MyNumber.Length - DotIndex);
DotIndex = Int32.Parse(MyNumber);
//MessageBox.Show(MyNumber); just to show the result!
It will return "2" for an input like "2.00000000e+1" AND "28" for "2.8000000e+1"!