ASP.NET

Moderators: None (Apply to moderate this forum)
Number of threads: 1733
Number of posts: 3304

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
inaccessible due to its protection level Posted by ac77 on 23 Jun 2003 at 9:01 AM
I've been having great difficulty with this, so hopefully someone more knowledgeable than myself can help out.

I'm basically trying to create a data grid from a code behind file. I have a file called index.aspx and a code behind file called ThePageBase.cs. In addition I have a namspace called DCTM in which I encapsulate my business logic and data access logic.

My code works great, but it breaks when I try and add paging using the following line:

mygrid.OnPageIndexChanged="change_Page";

The error is as follows:

Compiler Error Message: CS0122: 'System.Web.UI.WebControls.DataGrid.OnPageIndexChanged(System.Web.UI.WebControls.DataGridPageChangedEventArgs)' is inaccessible due to its protection level


I'm not sure what I need to do. For the sake of debugging I declared everything in my code behind file to be public. Below is what my code looks like:

index.aspx
---------
<%@ Page Language="C#" Inherits="ThePageBase" src="ThePageBase.cs" ContentType="text/html" ResponseEncoding="iso-8859-1" %>

<form runat="server" id="myform">
<p><asp:label runat="server" id="TheResult" /></p>
</form>

-----



ThePageBase.cs
--------------

using System;
using System.Web;
using System.Web.UI;

using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.OleDb;
using System.Text;
using System.Net;
using System.IO;
using System.Drawing;

using DCTM;


public class ThePageBase : System.Web.UI.Page {

public HtmlForm myform;
public DataGrid mygrid = new DataGrid();
protected Label TheResult;

public void Page_Load(Object Source, EventArgs E) {

if (!IsPostBack) {
CreateBindData();
}
}

void CreateBindData() {

BizObject bus = new BizObject("Provider=OraOLEDB.Oracle;Data Source=mysourse;User Id=myuser;Password=mypass");
DataSet ds = bus.GetData();
myform.Controls.Add(MakeGrid(ds));
}

public DataGrid MakeGrid(DataSet datas) {

mygrid.CellPadding=5;
mygrid.CellSpacing=1;
mygrid.BorderWidth=1;
mygrid.Width=550;
mygrid.BorderWidth=0;
mygrid.Font.Size=8;
mygrid.Font.Name="Arial";
mygrid.AutoGenerateColumns=false;
mygrid.EnableViewState=true;

BoundColumn Title = new BoundColumn();
BoundColumn Location = new BoundColumn();
BoundColumn EventType = new BoundColumn();

Title.HeaderText="Title";
Title.DataField="TITLE";
Location.HeaderText="Location";
Location.DataField="EVENT_LOCATION";
EventType.HeaderText="Type";
EventType.DataField="EVENT_TYPE";

mygrid.Columns.AddAt(0, Title);
mygrid.Columns.AddAt(1, Location);
mygrid.Columns.AddAt(2, EventType);

mygrid.HeaderStyle.HorizontalAlign=HorizontalAlign.Left;
mygrid.HeaderStyle.Font.Bold=true;
mygrid.HeaderStyle.BackColor=ColorTranslator.FromHtml("White");
mygrid.HeaderStyle.ForeColor=ColorTranslator.FromHtml("Black");

mygrid.ItemStyle.BackColor=ColorTranslator.FromHtml("#DAE7F7");
mygrid.AlternatingItemStyle.BackColor=ColorTranslator.FromHtml("#C8D5E5");

mygrid.AllowPaging=true;
mygrid.PageSize=10;
mygrid.OnPageIndexChanged="change_Page";
mygrid.PagerStyle.Mode = PagerMode.NextPrev;
mygrid.PagerStyle.NextPageText="next";
mygrid.PagerStyle.PrevPageText="previous";

mygrid.DataSource = datas;
mygrid.DataBind();
return mygrid;
}

public void change_Page(Object sender, DataGridPageChangedEventArgs e) {

mygrid.CurrentPageIndex = e.NewPageIndex;
CreateBindData();
}


// output html page with template
protected override void Render(HtmlTextWriter writer) {
writer.Write( @" <html> <head><title> Careers </title></head>");
writer.Write( readHtmlPage("http://mysite/templates/master/head.asp") );
writer.Write( @"<div style=""font-family: arial; font-size: 10px;"">" );

base.Render( writer );

writer.Write( @" </div>" );
writer.Write( readHtmlPage("http:/mysite/templates/master/tail.asp") );
}


private String readHtmlPage(string url) {
WebResponse objResponse;
WebRequest objRequest = System.Net.HttpWebRequest.Create(url);
objResponse = objRequest.GetResponse();
StreamReader sr = new StreamReader(objResponse.GetResponseStream());
return sr.ReadToEnd();
}

}

---------------


Thanks!!!
Report
Re: inaccessible due to its protection level Posted by cybermacgyver on 1 Jul 2003 at 5:46 AM
Try using Shared



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.