 |
| ASP.NET 3.5 Basics If you are new to ASP or ASP.NET programming with version 3.5, this is the forum to begin asking questions. Please also see the Visual Web Developer 2008 forum. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the ASP.NET 3.5 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
|

July 15th, 2009, 12:43 PM
|
|
Authorized User
|
|
Join Date: Jun 2009
Posts: 66
Thanks: 22
Thanked 0 Times in 0 Posts
|
|
DataView view
Hello all,
I have the following code. My table has more than 200 rows. I want to display the table and the export to excel link when the query pulls <= 200 rows. If it pulls more than 200 rows then I want the user to have the export to excel link only. I have the following code:
DataView view = ds.Tables[0].DefaultView;
resultsDatagrid.DataSource = view;
resultsDatagrid.DataBind();
resultsDatagrid.Visible = true; [[if I make it false, then the export to excel link doesn't work!!!]]
resultsLabel.Text = "More than 200 results found. Please Click the Export To Excel Link to Download the Results.";
resultsLabel.Visible = true;
exportLinkbutton.Visible = true;
If anyone can help me with this I will be grateful...
thanks in advance.
|
|

July 16th, 2009, 09:28 AM
|
 |
Wrox Author
|
|
Join Date: Jan 2008
Posts: 923
Thanks: 12
Thanked 166 Times in 162 Posts
|
|
Try this:
In <head> of page:
Code:
<style type="text/css">
hide {
display: none;
{
</style>
Then, do this:
Code:
DataView view = ds.Tables[0].DefaultView;
resultsDatagrid.DataSource = view;
resultsDatagrid.DataBind();
resultsDatagrid.CssClass = "hide";
resultsLabel.Text = "More than 200 results found. Please Click the Export To Excel Link to Download the Results.";
resultsLabel.Visible = true;
exportLinkbutton.Visible = true;
|
|

July 16th, 2009, 10:11 AM
|
|
Authorized User
|
|
Join Date: Jun 2009
Posts: 66
Thanks: 22
Thanked 0 Times in 0 Posts
|
|
My code is in .aspx.cs file where I don't have any html code.....it's just the C# code.....so I can not put any style tag there, or can I?
Thank you for the previous reply.....
and thanks in advance for the next one
|
|

July 16th, 2009, 10:43 AM
|
 |
Wrox Author
|
|
Join Date: Jan 2008
Posts: 923
Thanks: 12
Thanked 166 Times in 162 Posts
|
|
You should be able to put the <style> tag under the <head> tag of the .aspx file that goes with your .aspx.cs file.
|
|
The Following User Says Thank You to Lee Dumond For This Useful Post:
|
|
|

July 16th, 2009, 11:01 AM
|
|
Authorized User
|
|
Join Date: Jun 2009
Posts: 66
Thanks: 22
Thanked 0 Times in 0 Posts
|
|
yes, I have done that already but it didn't work....the thing is from the code what I have understood is, when the Export to Exscel link is clicked the following method is executed, where it needs the data to be displayed into the "resultsDatagrid.Visible = true;" line, other than that it's not working. to get the data to be exported to excel the code needs to have the data into the Datagrid (if it can be implemented without that it would be great.......I couldn't yet figure out how!!):
private void exportLinkbutton_Click(object sender, System.EventArgs e)
{
DataGridItem tblGrid=resultsDatagrid.Items[0];
ArrayList alLinks= new ArrayList();
TableCell TC;
LinkButton LB;
for(int i=0; i<tblGrid.Cells.Count - 1; i++)
{
TC=tblGrid.Cells[i];
if(TC.Controls.Count> 0)
{
LB=(LinkButton)TC.Controls[0];
resultsDatagrid.Items[0].Cells[i].Controls.Clear();
resultsDatagrid.Items[0].Cells[i].Text=LB.Text;
}
else
LB=new LinkButton();
alLinks.Add(LB);
}
Response.ContentType = "application/vnd.ms-excel";
Response.Charset = "";
resultsDatagrid.EnableViewState = false;
System.IO.StringWriter tw = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter hw = new System.Web.UI.HtmlTextWriter(tw);
resultsDatagrid.RenderControl(hw);
//TextWriter TW= File.CreateText(Server.MapPath("ExportToExcel.xls" ));
Response.Write(tw.ToString());
Response.End();
for(int i=0; i<tblGrid.Cells.Count - 1; i++)
{
LB = (LinkButton)alLinks[i];
//TC=tblGrid.Rows[0].Cells[i];
resultsDatagrid.Items[0].Cells[i].Controls.Add(LB);
}
}
|
|

July 16th, 2009, 11:17 AM
|
 |
Wrox Author
|
|
Join Date: Jan 2008
Posts: 923
Thanks: 12
Thanked 166 Times in 162 Posts
|
|
Sorry, made a slight mistake...
The line I added should not replace the Visible = true line. You do still need that line in there.
Code:
DataView view = ds.Tables[0].DefaultView;
resultsDatagrid.DataSource = view;
resultsDatagrid.DataBind();
resultsDataGrid.Visible = true;
resultsDatagrid.CssClass = "hide";
resultsLabel.Text = "More than 200 results found. Please Click the Export To Excel Link to Download the Results.";
resultsLabel.Visible = true;
exportLinkbutton.Visible = true;
This makes it "visible" on the server, but then the next line hides it on the client.
|
|
The Following User Says Thank You to Lee Dumond For This Useful Post:
|
|
|

July 16th, 2009, 12:04 PM
|
|
Authorized User
|
|
Join Date: Jun 2009
Posts: 66
Thanks: 22
Thanked 0 Times in 0 Posts
|
|
I have tried putting both the lines in but if I put
resultsDataGrid.Visible = true;
resultsDatagrid.CssClass = "hide";
both the lines then after clicking the Export to Excel link, the table with all the data (more than 10000 rows) is displayed below the link. But the requirement is to show the link only, not the table with data. When the users click on Export to Excel they will be able to download all the data results, but as more than 200 rows are pulled so they won't be able to see the data from that page.
Thank you Lee for your tries and I am sorry for bugging you like this.....but I am a newbie and don't know much about these......I apologize again for all the trouble.
|
|

July 16th, 2009, 12:19 PM
|
 |
Wrox Author
|
|
Join Date: Jan 2008
Posts: 923
Thanks: 12
Thanked 166 Times in 162 Posts
|
|
I'm assuming that the Export to Excel link causes a postback. That means you are going to have to reset the CssClass to "hide" again in the method that handles that postback, in order to make sure it stays hidden.
|
|
The Following User Says Thank You to Lee Dumond For This Useful Post:
|
|
|

July 16th, 2009, 12:45 PM
|
|
Authorized User
|
|
Join Date: Jun 2009
Posts: 66
Thanks: 22
Thanked 0 Times in 0 Posts
|
|
the post back would be in the same file or in the .aspx file.....but I have checked both but there is no post back.....
I don't understand what to do with it now... :(:(
|
|

July 16th, 2009, 02:07 PM
|
|
Authorized User
|
|
Join Date: Jun 2009
Posts: 66
Thanks: 22
Thanked 0 Times in 0 Posts
|
|
Should I write the post back inside the page_load method?
private void Page_Load(object sender, System.EventArgs e)
{
navMenu.SelectedMainItem = HIV.Controls.NavMenu.MainItems.QUERY;
navSubMenu.SelectedMainItem = HIV.Controls.NavMenu.MainItems.QUERY;
navSubMenu.SelectedSubItem = HIV.Controls.NavSubMenu.SubItems.RUN_QUERY;
If(!this.postback)
{
}
else
{
}
}
|
|
 |