Problems with LoginView and GridView

S

Sean Sims

recently added a LoginView to an existing page, it now looks like
this:

<%@ Page Language="C#" MasterPageFile="~/Site.master"
AutoEventWireup="true" CodeFile="AtPress.aspx.cs" Inherits="AtPress"
Title="Calendars Marked As 'At Press'" %>
<asp:Content ID="Content1" ContentPlaceHolderID="MainContent"
Runat="Server">
<asp:LoginView ID="LoginView1" runat="server">
<RoleGroups>
<asp:RoleGroup Roles="Administrators,Printers">
<ContentTemplate>
<script type="text/javascript"
language="javascript">
function SelectAllCheckboxes(spanChk){
// Added as ASPX uses SPAN for checkbox
var oItem = spanChk.children;
var
theBox=(spanChk.type=="checkbox")?spanChk:spanChk.children.item[0];
xState=theBox.checked;
elm=theBox.form.elements;

for(i=0;i<elm.length;i++)
if(elm.type=="checkbox" &&
elm.id!=theBox.id)
{
//elm.click();
if(elm.checked!=xState)
elm.click();
//elm.checked=xState;
}
}
</script>
<strong><span style="font-size: 14pt"><span
style="font-size: 24pt">Calendars Currently Marked As 'At
Press':</span>
<br /><br />
Click checkbox at top of list to select all
items.</span></strong><br />
<asp:GridView ID="GridView1" runat="server"
DataSourceID="CalendarsDataSource" AutoGenerateColumns="False"
DataKeyNames="pk_calendarID">
<Columns>
<asp:BoundField DataField="barcode"
HeaderText="Barcode" SortExpression="barcode" />
<asp:BoundField DataField="received"
HeaderText="Received" SortExpression="received" />
<asp:BoundField DataField="atpress"
HeaderText="At Press" SortExpression="atpress" />
<asp:TemplateField>
<ItemTemplate>
<asp:CheckBox
ID="SelectCalendarCheckbox" runat="server" />
</ItemTemplate>
<HeaderTemplate>
<input id="chkAll"
onclick="javascript:SelectAllCheckboxes(this);" runat="server"
type="checkbox" />
</HeaderTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
<br />
<asp:Button ID="btnToHandFinishing" runat="server"
Text="Move To 'At Hand Finishing' Status"
OnClick="btnToHandFinishing_Click" /><br />
<asp:ObjectDataSource ID="CalendarsDataSource"
runat="server" SelectMethod="GetCalendarsByStatusID"
TypeName="CalendarsBLL" OldValuesParameterFormatString="original_{0}">
<SelectParameters>
<asp:parameter DefaultValue="2"
Name="statusID" Type="Int32" />
</SelectParameters>
</asp:ObjectDataSource>
</ContentTemplate>
</asp:RoleGroup>
<asp:RoleGroup Roles="Finishers">
<ContentTemplate>
You Are Not Authorized To View This Page!
</ContentTemplate>
</asp:RoleGroup>
</RoleGroups>
</asp:LoginView>
</asp:Content>

And my code-behind page looks like this:

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.IO;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using KodakTableAdapters;

public partial class AtPress : System.Web.UI.Page
{
public CalendarsBLL methods = new CalendarsBLL();
protected void Page_Load(object sender, EventArgs e)
{
GridView1.Sort("received", SortDirection.Ascending);
}
protected void btnToHandFinishing_Click(object sender, EventArgs e)
{
//Use this method to copy the items in the
GridViewRowCollection object
//into the specified System.Array object, starting at the
specified index.
//The System.Array object can then be used to access the items
in the collection.

// Copy the items in the Rows collection into an array.
GridViewRow[] rowArray = new GridViewRow[GridView1.Rows.Count];
GridView1.Rows.CopyTo(rowArray, 0);

DataKey key;

// Iterate though the array and display the value in the first
cell of the row.
foreach (GridViewRow row in rowArray)
{
bool result =
((CheckBox)row.FindControl("SelectCalendarCheckbox")).Checked;
if (result)
{
byte fk_statusID = 3;
DateTime athandfinishing = DateTime.Now;
key = GridView1.DataKeys[row.RowIndex];
int pk_calendarID = ((int)key.Value);
// Get filename
string filename =
methods.GetCalendarFilename(pk_calendarID);
methods.UpdateCalendarAtHandFinishing(fk_statusID,
athandfinishing, pk_calendarID);
// Move Files to "READY_TO_PRINT" folder
string from = "C:\\HTTPPush\\READY_TO_PRINT\\" +
filename;
string to = "C:\\HTTPPush\\PROCESSED\\" + filename;
File.Move(from, to);
// Response.Redirect("~/AtHandFinishing.aspx");
}
}
GridView1.DataBind();
}

}

And I get the following error:

Compilation Error
Description: An error occurred during the compilation of a resource
required to service this request. Please review the following specific
error details and modify your source code appropriately.

Compiler Error Message: CS0103: The name 'GridView1' does not exist in
the current context

Source Error:

Line 17: protected void Page_Load(object sender, EventArgs e)
Line 18: {
Line 19: GridView1.Sort("received", SortDirection.Ascending);
Line 20: }
Line 21: protected void btnToHandFinishing_Click(object sender,
EventArgs e)

I'm assuming this is due to the GridView not showing for the "current"
user. However, even if I add an if (GridView1) before the
GridView1.Sort it still fails. How can I test to see if GridView1
exists, and if so then execute the code...otherwise ignore the code.
I'm sure there's a simple answer, that I should probably know, but I
can't seem to come up with it. Thanks in advance for any help!

-Sean
 

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

Staff online

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,012
Latest member
RoxanneDzm

Latest Threads

Top