Wrox Programmer Forums
|
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
 
Old July 15th, 2009, 12:43 PM
Authorized User
 
Join Date: Jun 2009
Posts: 66
Thanks: 22
Thanked 0 Times in 0 Posts
Default 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.
 
Old July 16th, 2009, 09:28 AM
Lee Dumond's Avatar
Wrox Author
 
Join Date: Jan 2008
Posts: 923
Thanks: 12
Thanked 166 Times in 162 Posts
Default

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;
__________________
Visit my blog at http://leedumond.com
Follow me on Twitter: http://twitter.com/LeeDumond

Code:
if (this.PostHelpedYou)
{
   ClickThanksButton(); 
}
 
Old July 16th, 2009, 10:11 AM
Authorized User
 
Join Date: Jun 2009
Posts: 66
Thanks: 22
Thanked 0 Times in 0 Posts
Default

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
 
Old July 16th, 2009, 10:43 AM
Lee Dumond's Avatar
Wrox Author
 
Join Date: Jan 2008
Posts: 923
Thanks: 12
Thanked 166 Times in 162 Posts
Default

You should be able to put the <style> tag under the <head> tag of the .aspx file that goes with your .aspx.cs file.
__________________
Visit my blog at http://leedumond.com
Follow me on Twitter: http://twitter.com/LeeDumond

Code:
if (this.PostHelpedYou)
{
   ClickThanksButton(); 
}
The Following User Says Thank You to Lee Dumond For This Useful Post:
skhan (July 16th, 2009)
 
Old July 16th, 2009, 11:01 AM
Authorized User
 
Join Date: Jun 2009
Posts: 66
Thanks: 22
Thanked 0 Times in 0 Posts
Default

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);
}
}
 
Old July 16th, 2009, 11:17 AM
Lee Dumond's Avatar
Wrox Author
 
Join Date: Jan 2008
Posts: 923
Thanks: 12
Thanked 166 Times in 162 Posts
Default

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.
__________________
Visit my blog at http://leedumond.com
Follow me on Twitter: http://twitter.com/LeeDumond

Code:
if (this.PostHelpedYou)
{
   ClickThanksButton(); 
}
The Following User Says Thank You to Lee Dumond For This Useful Post:
skhan (July 16th, 2009)
 
Old July 16th, 2009, 12:04 PM
Authorized User
 
Join Date: Jun 2009
Posts: 66
Thanks: 22
Thanked 0 Times in 0 Posts
Default

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.
 
Old July 16th, 2009, 12:19 PM
Lee Dumond's Avatar
Wrox Author
 
Join Date: Jan 2008
Posts: 923
Thanks: 12
Thanked 166 Times in 162 Posts
Default

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.
__________________
Visit my blog at http://leedumond.com
Follow me on Twitter: http://twitter.com/LeeDumond

Code:
if (this.PostHelpedYou)
{
   ClickThanksButton(); 
}
The Following User Says Thank You to Lee Dumond For This Useful Post:
skhan (July 16th, 2009)
 
Old July 16th, 2009, 12:45 PM
Authorized User
 
Join Date: Jun 2009
Posts: 66
Thanks: 22
Thanked 0 Times in 0 Posts
Default

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... :(:(
 
Old July 16th, 2009, 02:07 PM
Authorized User
 
Join Date: Jun 2009
Posts: 66
Thanks: 22
Thanked 0 Times in 0 Posts
Default

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
{

}
}





Similar Threads
Thread Thread Starter Forum Replies Last Post
Design view or source view tab doesnt appear Muddasar BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 2 March 25th, 2009 04:16 AM
Design view or source view tab doesnt appear Muddasar BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 0 March 24th, 2009 08:18 PM
Urgent - Send mail with plain view and html view ashish.dadhwal ASP.NET 2.0 Professional 0 November 27th, 2008 01:49 AM
Help Grid View Drop Down List, view all jskinner123 ASP.NET 2.0 Basics 0 November 25th, 2007 06:25 PM
populate details view or list view non empty rows iinfoque ASP.NET 2.0 Basics 0 March 11th, 2007 06:11 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.