|
Is there any way to get sorting to work while using these dynamic headers?
|
|
|
|
|
how to use this for more than one gridview on same page.i worked on this but there is some issues pls help me
|
|
|
|
|
You didn't tell the problems u faced.
|
|
|
|
|
i used two gridviews on same page.the only diffrence of both grid headers is TPMU for 1st grid and DPMU for 2nd grid.used two rowcreated events.but the output shows one grid with diffrent formate of headers and sub headers.
headers ("S.NO,TPMU,NDCCs Established,NDCCs Sent Report,Members eligible for training|Pregnant,Members eligible for training|Lactating,Members eligible for training|Total,Total members attended trainings| Pregnant,Total members attended trainings| Lactating,Total members attended trainings| Total,No.of Members attended trainings on maternal health care practices|In Number| Pregnant,No.of Members attended trainings on maternal health care practices|In Number| Lactant,No.of Members attended trainings on maternal health care practices|In Percentage|Pregnant ,No.of Members attended trainings on maternal health care practices|In Percentage|Lactant ,No.of Members attended trainings on Child care Practices| In Number|Pregnant ,No.of Members attended trainings on Child care Practices| In Number|Lactant ,No.of Members attended trainings on Child care Practices| In Percentage| Pregnant ,No.of Members attended trainings on Child care Practices| In Percentage| Lactant ,No.of Members attended trainings on Community health care practices|In Number | Pregnant ,No.of Members attended trainings on Community health care practices|In Number | Lactant ,No.of Members attended trainings on Community health care practices|In Percentage | Pregnant ,No.of Members attended trainings on Community health care practices|In Percentage | Lactant ")
|
|
|
|
|
I didn't understand TPMU/DPMU.
Have you created two objects of DynamicHeaders class and used them in the appropriate render methods?
Post the render methods and DynamicHeaders object creation code.
|
|
|
|
|
this is sample code for two grids pls check once
<asp:gridview id="GridViewWithDynamicHeader" runat="server"
="" onrowcreated="GridViewWithDynamicHeader_RowCreated" datasourceid="XmlDataSourceSales">
<asp:xmldatasource id="XmlDataSourceSales" runat="server"
="" datafile="~/SampleData.xml">
<asp:gridview id="GridView1" runat="server"
="" onrowcreated="GridView1_RowCreated" datasourceid="XmlDataSourceSales">
<asp:xmldatasource id="XmlDataSource1" runat="server"
="" datafile="~/SampleData.xml">
code behind
using System;
using System.Collections;
using System.Collections.Generic;
using System.Drawing;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class _Default : System.Web.UI.Page
{
string headevalues = string.Empty;
protected void Page_Load(object sender, EventArgs e)
{
}
public void headervalues(string values)
{
headevalues = values;
}
public void RenderHeader(HtmlTextWriter writer, Control ctl)
{
DynamicHeaders dynHead = new DynamicHeaders(headevalues);
ArrayList Headers = dynHead.ParseHeader();
Color[] bkColors = { Color.LightSkyBlue, Color.LightBlue, Color.LightSkyBlue };
int[] fntSizes = { 16, 14, 12 };
for (int j = 0; j < Headers.Count; j++)
{
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.Font.Name = "arial, helvetica,sans-serif";
item.Font.Size = fntSizes[j];
item.BackColor = bkColors[j];
item.RenderControl(writer);
}
writer.WriteEndTag("TR");
if (j < Headers.Count - 1)
writer.RenderBeginTag("TR");
}
}
protected void GridViewWithDynamicHeader_RowCreated(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.Header)
//Render the header "SOAP|Bath Soap|Pink Soap,SOAP|Bath Soap|White Soap,SOAP|Toilet Soap,SHAMPOO"
{
headervalues("SOAP|Bath Soap|Pink Soap,SOAP|Bath Soap|White Soap,SOAP|Toilet Soap,SHAMPOO");
e.Row.SetRenderMethodDelegate(new RenderMethod(RenderHeader));
}
}
protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.Header)
//Render the header "SOAP|Bath Soap|Pink Soap,SOAP|Bath Soap|White Soap,SOAP|Toilet Soap,SHAMPOO"
{
headervalues("SOAP1|Bath Soap|Pink Soap,SOAP1|Bath Soap|White Soap,SOAP1|Toilet Soap,SHAMPOO");
e.Row.SetRenderMethodDelegate(new RenderMethod(RenderHeader));
}
}
}
|
|
|
|
|
You have not told again about the problem. I guess you are getting both the data grid with "SOAP1" as header.
Have you tried to debug and found out the reason? Or simply dumped on me to debug and give you a working solution?
Put a break point in your "public void headervalues(string values)" method and you should figure it out.
Please ask questions to clear your understandings and not to debug your code and give you a solution.
|
|
|
|
|
your guess is correct,i am getting same headers for both gridview.how to solve this.
i tried to debug,but i unable to find the solution.thank u for ur reply.
|
|
|
|
|
It's a pity that even after pointing you the debug location, you cannot debug. This is my last reply on this and please do not ask for any further help.
public void RenderHeader1(HtmlTextWriter writer, Control ctl)
{
DynamicHeaders dynHead = new DynamicHeaders("SOAP|Bath Soap|Soap,SOAP|Bath Soap|Soap,SOAP|Toilet Soap,SHAMPOO");
ArrayList Headers = dynHead.ParseHeader();
RenderHeader(Headers, writer, ctl);
}
public void RenderHeader2(HtmlTextWriter writer, Control ctl)
{
DynamicHeaders dynHead = new DynamicHeaders("SOAP1|Bath Soap|Soap,SOAP1|Bath Soap|Soap,SOAP1|Toilet Soap,SHAMPOO");
ArrayList Headers = dynHead.ParseHeader();
RenderHeader(Headers, writer, ctl);
}
public void RenderHeader(ArrayList Headers, HtmlTextWriter writer, Control ctl)
{
Color[] bkColors = { Color.LightSkyBlue, Color.LightBlue, Color.LightSkyBlue };
int[] fntSizes = { 16, 14, 12 };
for (int j = 0; j < Headers.Count; j++)
{
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.Font.Name = "arial, helvetica,sans-serif";
item.Font.Size = fntSizes[j];
item.BackColor = bkColors[j];
item.RenderControl(writer);
}
writer.WriteEndTag("TR");
if (j < Headers.Count - 1)
writer.RenderBeginTag("TR");
}
}
protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.Header)
{
e.Row.SetRenderMethodDelegate(new RenderMethod(RenderHeader1));
}
}
protected void GridView2_RowCreated(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.Header)
{
e.Row.SetRenderMethodDelegate(new RenderMethod(RenderHeader2));
}
}
|
|
|
|
|
Thank u for your reply,and i am sorry for irritated you.i am new to this type of dynamic gridview coding.
my requirement is over.but is it correct way to create RenderHeader method for each gridview.
ANYWAY THNK U SOO MUCH FOR HELP.
|
|
|
|
|
Sir Thank You for the Solution. But I am facing one little error. When I am trying with this data which is given below.
"Laser Saving Production|Laser|LR",
"Brkgs|Value Loss|LR"
.
Now when I am trying to display this format on webpage,program is merging last element e.g "LR" and format become inappropriate.It will not showing format properly. So Can you please help me out. How can i resolve it ?
Bhavik
|
|
|
|
|
I will be able to help, if you describe the expected output with your sample data.
|
|
|
|
|
Sir Please Click here : http://snk.to/f-chm8g9ic[^] . This is your program where i have entered my data. Please run it and see the output and Please help me to solve it.
|
|
|
|
|
Sir,Please Click On this link http://www.filesnack.com/files/chm8g9ic[^],Download it and run it and Please examine the output.. This is Your program in which I have input my data. Kindly requesting u please help me out.
|
|
|
|
|
U have send me the code. I have requested for the layout, as per the data ("Laser Saving Production|Laser|LR","Brkgs|Value Loss|LR"). Check the table format at the top of the article and show your expected table output.
|
|
|
|
|
|
Since you do not want to merge the last row, merging should be skipped for last row.
In the "public ArrayList ParseHeader()" method of DynamicHeaders.cs file you should do that.
for (int i = 0; i < HeaderRows; i++)
Here u should skip the last row, hence change the condition
for (int i = 0; i < HeaderRows-1; i++)
similarly
for (int j = 0; j < HeaderCols; j++)
{
for (int i = 0; i < HeaderRows-1; i++)
Not tested. May be the second change is not required. You have to test and adjust. Good Luck.
|
|
|
|
|
Sir, First time when i faced this error,I have tried to solve it but I could not fix the error. As per your suggestion I have modified the code. But still Facing the same Problem.
Thank You.
|
|
|
|
|
I have locally tested the code with 1st change only and its working.
You had another problem of same column value in Row 2 also.
So change the code
for (int i = 0; i < HeaderRows-2; i++)
I hate spoon feeding. You cannot just ask for help without understanding the code and blindly using it.
You should first understand the logic and modify as per your requirements. This is the last reply from me on this. Good Luck.
modified 22-Jan-14 4:59am.
|
|
|
|
|
Okay Sir and Thank you very much for help me out.
|
|
|
|
|
|
After your merging The Colunn Sorting looses.
Also, if we click on button (server control) on page with grid after merging - grid returns to initial state.
|
|
|
|
|
I use this code for exporting
Response.Clear();
Response.Buffer = true;
Response.AddHeader("content-disposition", "attachment;filename=List.xls");
Response.Charset = "";
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.ContentType = "application/vnd.xls";
StringWriter stringWrite = new StringWriter();
System.Web.UI.HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);
dgData.RenderControl(htmlWrite);
Response.Write(stringWrite.ToString());
Response.Flush();
Response.End();
Is There any solution?
|
|
|
|
|
Did this long back. You can try the following (not compiled but should be Ok)
Response.Clear();
Response.ClearHeaders();
Response.AddHeader("content-disposition", "attachment;filename=List.xls");
Response.Buffer = true;
Response.ContentType = "application/vnd.ms-excel";
Response.Charset = "";
System.Web.UI.HtmlTextWriter htmlWrite = new HtmlTextWriter(new StringWriter());
dgData.RenderControl(htmlWrite);
Response.Write(htmlWrite.InnerWriter.ToString());
Response.End();
|
|
|
|
|
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
|
|
|
|
|