accessing gridview from master page

H

hazz

A treeview control should be able to select various aspx pages in the site.
(using sitemap)
One content page will have a gridview, accessed through a content place
holder while another aspx page will contain a report viewer, accessed
through the same contentplaceholder. At least that is how I understand it.

If I want the master page to contain a button to create an excel file from
the gridview contents, how do I access the gridview on the aspx page
containing the gridview? Findcontrol isn't finding the GridView as per;

protected void buttonCreateExcel_Click(object sender, EventArgs e)
{
// get control from aspx page that contains the GridView and
MasterPageFile="~/MasterPage.master"
Control myControl1 = FindControl("GridView1"); //returns
null unfortunately
if (myControl1 != null)
{
Response.ContentType = "application/vnd.xls";
System.IO.StringWriter stringWrite = new
System.IO.StringWriter();
System.Web.UI.HtmlTextWriter htmlWrite = new
HtmlTextWriter(stringWrite);
GridView1.RenderControl(htmlWrite);


Thank you,
-Greg
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,236
Members
46,822
Latest member
israfaceZa

Latest Threads

Top