|
It doesn't work either.
When i trace, it seem missing '</table>' closing tag, and there are double '</tr></tr>' without begin tag '<tr>', this cause the error when the html tag not well formed...
but now i confused where is the code that make this happen...
It resulting error...
This error happen when using Ajax with Update Panel....
My Format is :
DynamicHeaders dynHead = new DynamicHeaders("No.,ID Unit Kerja,Nama Unit Kerja,ESL,STRUKTURAL|ESELON I|ISL,STRUKTURAL|ESELON I|KR,STRUKTURAL|ESELON I|KT,STRUKTURAL|ESELON I|HD,STRUKTURAL|ESELON I|BD,STRUKTURAL|ESELON II|ISL,STRUKTURAL|ESELON II|KR,STRUKTURAL|ESELON II|KT,STRUKTURAL|ESELON II|HD,STRUKTURAL|ESELON II|BD,STRUKTURAL|ESELON III|ISL,STRUKTURAL|ESELON III|KR,STRUKTURAL|ESELON III|KT,STRUKTURAL|ESELON III|HD,STRUKTURAL|ESELON III|BD,STRUKTURAL|ESELON IV|ISL,STRUKTURAL|ESELON IV|KR,STRUKTURAL|ESELON IV|KT,STRUKTURAL|ESELON IV|HD,STRUKTURAL|ESELON IV|BD");
-- Modified Wednesday, August 24, 2011 3:31 PM
|
|
|
|
|
The code I gave yesterday worked for me without Ajax and update panel. U can
1) Check the source (view source) befor export and see if there are problems with TAG.
2) If everything is fine in step 1, then the problem is while exoprting. It will try to render the header again and the above header string should be avaialable. Is it there in session or some other place?
|
|
|
|
|
Thank u for your response....
I try your demo with format header :
SOAP|Bath Soap|Pink Soap,SOAP|Bath Soap|White Soap,SOAP|Toilet Soap,SHAMPOO
And without Ajax, and I change GridView with DataGrid
On IE i have view the page source and dump html tag like below:
<table cellspacing="0" cellpadding="4" rules="all" border="1" id="GridViewWithDynamicHeader" style="width:100%;border-collapse:collapse;">
<tr>
<td align="center" valign="middle" colspan="3" rowspan="1" style="background-color:LightSkyBlue;font-family:arial, helvetica,sans-serif;font-size:16pt;font-weight:bold;">SOAP</td><td align="center" valign="middle" colspan="1" rowspan="3" style="background-color:LightSkyBlue;font-family:arial, helvetica,sans-serif;font-size:16pt;font-weight:bold;">SHAMPOO</td></TR><tr>
<td align="center" valign="middle" colspan="2" rowspan="1" style="background-color:LightBlue;font-family:arial, helvetica,sans-serif;font-size:14pt;font-weight:bold;">Bath Soap</td><td align="center" valign="middle" colspan="1" rowspan="2" style="background-color:LightBlue;font-family:arial, helvetica,sans-serif;font-size:14pt;font-weight:bold;">Toilet Soap</td></TR><tr>
<td align="center" valign="middle" colspan="1" rowspan="1" style="background-color:LightSkyBlue;font-family:arial, helvetica,sans-serif;font-size:12pt;font-weight:bold;">Pink Soap</td><td align="center" valign="middle" colspan="1" rowspan="1" style="background-color:LightSkyBlue;font-family:arial, helvetica,sans-serif;font-size:12pt;font-weight:bold;">White Soap</td></TR>
</tr><tr>
<td>100</td><td>200</td><td>300</td><td>400</td>
</tr><tr>
<td>10</td><td>20</td><td>30</td><td>40</td>
</tr><tr>
<td>1</td><td>2</td><td>3</td><td>4</td>
</tr><tr>
<td>100</td><td>200</td><td>300</td><td>400</td>
</tr>
</tr>
So this is missing table closing tag and invalid 'tr' tag...
I also try with standard format header :
Pink Soap,White Soap,Toilet Soap,SHAMPOO
On IE dump like below:
<table cellspacing="0" cellpadding="4" rules="all" border="1" id="GridViewWithDynamicHeader" style="width:100%;border-collapse:collapse;">
<tr>
<td align="center" valign="middle" colspan="1" rowspan="1" style="background-color:LightSkyBlue;font-family:arial, helvetica,sans-serif;font-size:16pt;font-weight:bold;">Pink Soap</td><td align="center" valign="middle" colspan="1" rowspan="1" style="background-color:LightSkyBlue;font-family:arial, helvetica,sans-serif;font-size:16pt;font-weight:bold;">White Soap</td><td align="center" valign="middle" colspan="1" rowspan="1" style="background-color:LightSkyBlue;font-family:arial, helvetica,sans-serif;font-size:16pt;font-weight:bold;">Toilet Soap</td><td align="center" valign="middle" colspan="1" rowspan="1" style="background-color:LightSkyBlue;font-family:arial, helvetica,sans-serif;font-size:16pt;font-weight:bold;">SHAMPOO</td></TR>
</tr><tr>
<td>100</td><td>200</td><td>300</td><td>400</td>
</tr><tr>
<td>10</td><td>20</td><td>30</td><td>40</td>
</tr><tr>
<td>1</td><td>2</td><td>3</td><td>4</td>
</tr><tr>
<td>100</td><td>200</td><td>300</td><td>400</td>
</tr>
</table>
There is exist closing tag...
I really don't know why this could happen
It same either when i try on Firefox....
|
|
|
|
|
Set a breakpoint, debug the method
RenderHeader .
|
|
|
|
|
Thank u...
The problem is solved....
Instead using internal render such as RenderBeginTag and WriteAndTag
I am using Write and it is solved (strange is it?)...
It seem Internal Render has some invalid parsing...
So i modified the code like below:
for (int j = 0; j < Headers.Count; j++)
{
if (j > 0)
{
writer.Write("<tr>");
}
List<DynamicHeaderCell> HeaderRow = (List<DynamicHeaderCell>)Headers[j];
for (int i = 0; i < HeaderRow.Count; i++)
{
TableCell item = new TableCell();
item.Text = HeaderRow[i].Header;
item.ColumnSpan = HeaderRow[i].ColSpan;
item.RowSpan = HeaderRow[i].RowSpan;
item.HorizontalAlign = HorizontalAlign.Center;
item.VerticalAlign = VerticalAlign.Middle;
item.Font.Bold = true;
item.BackColor = System.Drawing.Color.FromName("#663300");
item.ForeColor = System.Drawing.Color.White;
item.RenderControl(writer);
}
if (j < Headers.Count - 1)
{
writer.Write("</tr>");
}
}
|
|
|
|
|
Good to know that it worked.
|
|
|
|
|
Hi nice article..
I have a table in my database called "Diagnostic" and in this table I have some fields:
idDiagnostic DiagnosticName
1 Good condition
2 Regular Condition
3 Light
4 Glass
I would like to know how can I make a string from that table in order to do the same as u did
I appreciate your help
BRIPEBAQR
|
|
|
|
|
Couldn't make out your requirement. This is mianly for Hierarchical data. Two cases can be there
Case 1: Your Hierarchical table is fixed. Example - Parent: A, B. Child of A: A1, A2 and tis will never change.You can hard code the string in the code.
Case 2: Your Hierarchical table is not fixed. Consider the above example, some day you can introduce C which can be parent of A and so on. You have to create the string dynamically in database.
In terms of logic it should be something like this:
1. Find all the items which are not parents.
2. For each item in step 1, construct a string by adding the parent till parent is available.
3. Combine all the strings in step 2
Depending upon which database you are using, you have to figure out thw way to do this. For example if the database is ORACLE, you can construct a query using connect by parent or child clause.
|
|
|
|
|
First of all, THANKS A LOT for this teaching. Clean and correct inside ASP.NET concepts and Universe.
About the bug, if trying to generete a header like "Product1|Quantity|Total Value, Product2|Quantity|Total Value", there is problems to organize that. So to correct this, there is just an else missing.
Inside "public class DynamicHeaders", there is the method "public ArrayList ParseHeader()". Here, when comparing actual cell with next cell, when the next cell is differente than actual, there is no need to continue comparing. Stopping here and folowing to next actual cell corrects the problem for the above sample header.
if (HeaderCell1.Header.Equals(HeaderCell2.Header))
{
HeaderCell1.ColSpan++;
HeaderCells.SetValue(null, i, k);
}
else
break;
The else above is the else missing.
|
|
|
|
|
Thanks for your solution, but there are still bug in my code, i.e, when generating a header like "Clock|Red Clock|Big Clock", a bug comes up.
Moreover, if there are cells with the same name next to each other in the different columns, similar mistakes then comes as you described.
Can you do me a favor?
Thanks again!
|
|
|
|
|
Please update when you get the better solution for the Same.
Even I have the same task to be achieved and have been trying with content presenter and itempresenter putting them in different panel using group style. Tell me If I am on the write track.
|
|
|
|
|
Hi,
Your article seems very useful. but is there a possiblity in creating the same with ASP.Net 1.1
Anjan
|
|
|
|
|
My initial work was on ASP.NET 1.1 as below
public class clsDynHeadingParsing
{
private String strToParse;
private int nRow;
private int nCol;
public ArrayList headerItems;
public clsDynHeadingParsing(String strInput, int row, int col, int nBlanks)
{
nRow = row;
nCol = col;
strToParse = "";
for(int i=0; i<nBlanks; i++)
{
strToParse = strToParse + " ,";
nCol++;
}
strToParse = strToParse + strInput;
}
public ArrayList parseString()
{
String [] strItems = strToParse.Split(',');
Array strHeader = Array.CreateInstance(typeof(String),nRow,nCol);
Array nVS = Array.CreateInstance(typeof(Int32),nRow,nCol);
Array nHS = Array.CreateInstance(typeof(Int32),nRow,nCol);
headerItems = new ArrayList();
for(int i=0; i<nRow; i++)
{
for(int j=0; j<nCol; j++)
{
if(strItems[j]=="")
{
strHeader.SetValue("",i,j);
}
else
{
int nPipePos = strItems[j].IndexOf("|");
if(nPipePos == -1)
{
strHeader.SetValue(strItems[j],i,j);
strItems[j] = "";
}
else
{
strHeader.SetValue(
strItems[j].Substring(0, nPipePos),i,j);
strItems[j] = strItems[j].Substring(nPipePos+1);
}
}
}
}
for(int i=0; i<nRow; i++)
{
for(int j=0; j<nCol; j++)
{
if(strHeader.GetValue(i,j).ToString()=="")
{
nHS.SetValue(-1,i,j);
}
else
{
int k=1;
int hc=1;
while(i<nRow-1 && j+k<nCol && strHeader.GetValue(i,j).ToString().
Equals(strHeader.GetValue(i,j+k).ToString()))
{
hc++;
strHeader.SetValue("",i,j+k);
nHS.SetValue(-1,i,j+k);
k++;
}
nHS.SetValue(k,i,j);
j +=(k-1);
}
}
}
for(int j=0; j<nCol; j++)
{
for(int i=0; i<nRow; i++)
{
if(strHeader.GetValue(i,j).ToString()=="")
{
nVS.SetValue(-1,i,j);
}
else
{
int k=1;
int vc=1;
while(i+k<nRow && strHeader.GetValue(i+k,j).ToString() == "")
{
vc++;
strHeader.SetValue("",i+k,j);
nVS.SetValue(-1,i+k,j);
k++;
}
nVS.SetValue(k,i,j);
i +=(k-1);
}
}
}
for(int i=0; i<nRow; i++)
{
ArrayList header = new ArrayList();
for(int j=0; j<nCol; j++)
{
if(strHeader.GetValue(i,j).ToString()=="" ||
(Int32)nHS.GetValue(i,j) == -1 || (Int32)nVS.GetValue(i,j) == -1)
continue;
header.Add(FormCell(i+1, strHeader.GetValue(i,j).ToString(),
(Int32)nVS.GetValue(i,j), (Int32)nHS.GetValue(i,j)));
}
headerItems.Add(header);
}
return headerItems;
}
private TableCell FormCell(int headerLevel, String Text,int RowSpan,int ColumnSpan)
{
TableCell cell = new TableCell();
cell.Text = Text;
cell.RowSpan = RowSpan;
cell.ColumnSpan=ColumnSpan;
return cell;
}
}
modified on Friday, May 29, 2009 5:16 AM
|
|
|
|
|
how and where will i pass the header input for this one?
thanks and regards
anjan
|
|
|
|
|
In the DataGrid ItemCreated event, delegate the header rendering to a method as follow:
if(e.Item.ItemType == ListItemType.Header)
{
e.Item.SetRenderMethodDelegate(new RenderMethod(NewRenderMethod));
}
In the NewRenderMethod use the header collection
public void NewRenderMethod(HtmlTextWriter writer, Control ctl)
{
// Call the method of prev class to get the collection and use it
}
|
|
|
|
|
can you pass me the code for the render method for this
Thanks and Regards
Anjan
|
|
|
|
|
I get this...
Compiler Error Message: CS1525: Invalid expression term '>'
Line 18:
Line 19: HeaderCols = Headers.Count;
Line 20: HeaderRows = Headers.Max(H => H.HeaderDepth);
Line 21: ParseHeader();
Line 22: }
|
|
|
|
|
Sorry, I noticed this message today only. The code uses .NET 3.5 framework
|
|
|
|
|
The type or namespace name 'Linq' does not exist in the namespace 'System' (are you missing an assembly reference?) ..............
I even tried System.Core, but not in my web reference list.
plz help me with this
|
|
|
|
|
The code was developed using Visual Studio 2008, where LINQ is available. Are you using the same?
Anyhow this is not in use and you can delete the line(s).
|
|
|
|
|
|
How does it sort?
(2B)||(!2B)
|
|
|
|
|
It is a simple, but elegant solution
Fakher Halim
|
|
|
|
|