Can't find GridView in ASP - asp.net

I am brand new to asp and downloaded some example code of a shopping cart. When I created a new project in Visual Studio, added all the files in and tried to compile I got the following error.
Error 1 The name 'gvShoppingCart' does not exist in the current context c:\users\slaphappysmoker\documents\visual studio 2010\Projects\Shopcart\Shopcart\ViewCart.aspx.cs 21 3 Shopcart
However I can see where gvShoppingCart gets defined in the ViewCart.aspx file.
<%# Page Language="C#" AutoEventWireup="true" CodeFile="ViewCart.aspx.cs" Inherits="ViewCart" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Shopping Cart</title>
<link href="Styles/StyleSheet.css" rel="stylesheet" type="text/css" />
</head>
<body>
<form id="form1" runat="server">
<div class="container">
<h1>Shopping Cart</h1>
< Back to Products
<br /><br />
<asp:GridView runat="server" ID="gvShoppingCart" AutoGenerateColumns="false" EmptyDataText="There is nothing in your shopping cart." GridLines="None" Width="100%" CellPadding="5" ShowFooter="true" DataKeyNames="ProductId" OnRowDataBound="gvShoppingCart_RowDataBound" OnRowCommand="gvShoppingCart_RowCommand">
<HeaderStyle HorizontalAlign="Left" BackColor="#3D7169" ForeColor="#FFFFFF" />
<FooterStyle HorizontalAlign="Right" BackColor="#6C6B66" ForeColor="#FFFFFF" />
<AlternatingRowStyle BackColor="#F8F8F8" />
<Columns>
<asp:BoundField DataField="Description" HeaderText="Description" />
<asp:TemplateField HeaderText="Quantity">
<ItemTemplate>
<asp:TextBox runat="server" ID="txtQuantity" Columns="5" Text='<%# Eval("Quantity") %>'></asp:TextBox><br />
<asp:LinkButton runat="server" ID="btnRemove" Text="Remove" CommandName="Remove" CommandArgument='<%# Eval("ProductId") %>' style="font-size:12px;"></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="UnitPrice" HeaderText="Price" ItemStyle-HorizontalAlign="Right" HeaderStyle-HorizontalAlign="Right" DataFormatString="{0:C}" />
<asp:BoundField DataField="TotalPrice" HeaderText="Total" ItemStyle-HorizontalAlign="Right" HeaderStyle-HorizontalAlign="Right" DataFormatString="{0:C}" />
</Columns>
</asp:GridView>
<br />
<asp:Button runat="server" ID="btnUpdateCart" Text="Update Cart" OnClick="btnUpdateCart_Click" />
</div>
</form>
</body>
</html>
Here is the code that is calling the GridView in the ViewCart.aspx.cs file:
protected void BindData() {
// Let's give the data to the GridView and let it work!
// The GridView will take our cart items one by one and use the properties
// that we declared as column names (DataFields)
gvShoppingCart.DataSource = ShoppingCart.Instance.Items;
gvShoppingCart.DataBind();
}
How can I get the ViewCart.aspx.cs code file to recognize the ViewCart.aspx and the GridView contained within?
Edit: Added the function that calls the gridview.

Try to make sure that the gridview has a reference in the designer.cs file
protected global :: System.Web.UI.WebControls.GridView gvShoppingCart;

Related

My asp.net data grid won't reading from xml file

This is my first time using asp.net so pleaseaccept my apologies if this is a dumb question.
I am trying to make a web application that will work on our work sharepoint. the idea is a team of people can select when they are available to call or not and if they are the contact point that day so that people on different floors can see their availability without a line of sight.
i would normally make a basic php script but sharepoint doesnt like php and we cannot reference to external resources on our network.
The issue i have is the table that should be pulling data from the xml is just a blank page... originally it gave an error saying it couldnt find that data field and i realised i needed to use xpath to be more specific... it now doesnt give any error, like its finding the field but doesnt draw it. the code is below:
XML database:
<?xml version="1.0" encoding="utf-8" ?>
<CRM>
<agent>
<id>user1</id>
<name>name</name>
<turret>extension</turret>
<email>email</email>
<status>XXXXX</status>
<contact>N/A</contact>
</agent>
<agent>
<id>user2</id>
<name>Name 2</name>
<turret>extension</turret>
<email>email</email>
<status>XXXXX</status>
<contact>N/A</contact>
</agent>
<agent>
<id>user3</id>
<name>Name 3</name>
<turret>Extension Number</turret>
<email>email address</email>
<status>XXXXX</status>
<contact>N/A</contact>
</agent>
</CRM>
and the datagrid that should be pulling that data is here:
<%# Page Language="vb" AutoEventWireup="false" CodeBehind="CSTvisibility.aspx.vb" Inherits="CRM_availabilty.CSTvisibility" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:XmlDataSource ID="data" runat="server" DataFile="~/crmdata.xml" XPath="/agent"></asp:XmlDataSource>
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" BorderStyle="Ridge" DataSourceID="data">
<Columns>
<asp:BoundField DataField="name" HeaderText="CRM Agent" />
<asp:BoundField DataField="turret" HeaderText="Turret" />
<asp:BoundField DataField="email" HeaderText="Email" />
<asp:BoundField DataField="status" HeaderText="Available" />
<asp:BoundField DataField="contact" HeaderText="Contact Point" />
</Columns>
</asp:GridView>
</div>
</form>
</body>
</html>
Switch to TemplateField instead of BoundField. Then you have access to the XPath.
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false" DataSourceID="data">
<Columns>
<asp:TemplateField HeaderText="CRM Agent">
<ItemTemplate>
<%# XPath("name") %>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Turret">
<ItemTemplate>
<%# XPath("turret") %>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Email">
<ItemTemplate>
<%# XPath("email") %>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
The XPath in the XmlDataSource must be XPath="CRM/agent"

ASP.NET: Attribute passed to ascx descends to top-level control but not nested control

In my ASP.NET project (VB.NET) I have a self-coded user control called DocumentDisplay that I invoke with a TargetWebPage attribute:
<uc1:DocumentDisplay ID="DocumentDisplay" runat="server" TargetWebPage="EntityDocumentUpload"/>
The codebehind for the user control implements the public property TargetWebPage, and in the debugger I can see it is being set correctly. Also, in the user control (ascx) there is a yyySecureButton defined (line 9), which also has this public property defined in it, and this is being set as well. The problem is I need the property to descend all the way to the yyySecureCommandField defined (within the DomainGridView control) on line 25; this property is in the codebehind for that control as well, but it is not being set.
Can I pass the TargetWebPage attribute to the yyySecureCommandField from within the markup? If not, how best to do it?
The code below is identical to what I'm working with except that strings identifying my client have been changed to vvv, xxx, yyy, etc.
Many thanks for any response.
<%# Control Language="vb" AutoEventWireup="false" CodeBehind="DocumentDisplay.ascx.vb" Inherits="zzz.DocumentDisplay" %>
<xxx:ErrorSection ID="ErrorSection" runat="server"/>
<div class="FieldGroup">
<fieldset>
<legend>Documents</legend>
<xxx:InputField runat="server" ID="InputFieldDocumentType" FieldName="DocumentType" CssClass="DocumentField" SuppressRequiredIndicator="True" />
<xxx:InputField runat="server" ID="InputFieldDocumentName" FieldName="DocumentName" CssClass="DocumentField" SuppressRequiredIndicator="True" />
<div class="DocumentField"><label>Upload</label><input type="File" id="DocumentUpload" runat="server" /></div>
<div class="TableSectionCommandBar"><vvv:yyySecureButton id="ButtonUpload" runat="server" SecurityMode="Action" Text="Add" CssClass="StandardButton"/></div>
<div class="Spacer" />
<div class="TableSection">
<xxx:DomainGridView ID="GridViewDocuments" runat="server" AutoGenerateColumns="False" CssClass="StandardTable" DomainObjectName="zzz.Domain.Document,yyyLib" DataKeyNames="DocumentId" AlwaysRequiresDatabind="True" AllowSorting="True">
<Columns>
<xxx:FieldDefinitionField FieldName="DocumentType" ShowToolTip="True" SortExpression="DocumentType" />
<xxx:FieldDefinitionField FieldName="DocumentName" ShowToolTip="True" SortExpression="DocumentName" />
<xxx:FieldDefinitionField FieldName="DocumentDate" IsReadOnly="True" ShowToolTip="True" SortExpression="DocumentDate" />
<asp:TemplateField HeaderText="Doc" ItemStyle-HorizontalAlign="Center">
<ItemTemplate>
<asp:Hyperlink ID="LinkViewContentDocuments" runat="server" Visible="<%#Not String.IsNullOrEmpty(DirectCast(Container.DataItem, DocumentInformation).DocumentFileName)%>" NavigateUrl="<%#ResolveUrl(String.Format(CultureInfo.InvariantCulture, ApplicationUrls.ViewEntityDocuments, DirectCast(Container.DataItem, DocumentInformation).DocumentId))%>" ImageUrl="<%#ResolveUrl(ApplicationUrls.PaperclipImage)%>" ToolTip="<%#DirectCast(Container.DataItem, DocumentInformation).DocumentFileName%>" Text="<%#DirectCast(Container.DataItem, DocumentInformation).DocumentFileName%>" />
</ItemTemplate>
<EditItemTemplate>
<input type="File" id="UpdateDocumentUpload" runat="server" />
</EditItemTemplate>
</asp:TemplateField>
<vvv:yyySecureCommandField SecurityMode="Action" EditText="Edit" UpdateText="Update" CancelText="Cancel" DeleteText="Delete" ShowCancelButton="True" ShowEditButton="True" ShowDeleteButton="True" />
</Columns>
<EmptyDataTemplate>
<asp:Label ID="LabelNoEntityResults" runat="server" Text="There are currently no documents to display."></asp:Label>
</EmptyDataTemplate>
<RowStyle CssClass="ItemRow" />
<HeaderStyle CssClass="HeaderRow" />
<AlternatingRowStyle CssClass="AlternatingItemRow" />
<PagerStyle CssClass="PagingRow" />
</xxx:DomainGridView>
</div>
</fieldset>
</div>

Could not Update Text box control values

I am really frustrated to find a solution for my scenario. I have two gird when First grid is used show the shop information and the second grid is used to edit the offers related to the shop information. When the users edit the second grid i will just update the text box values related to the grid selection row. in my code behind file i can see the data fetching from the grid and assigning into the text boxes but when the function call (imgEdit_click) finished the page does not show the values. Editing functionality can be done in many ways but my scenario is what i explained earlier . I have the checked page there is no Postback action has been called after the method I could not find the solution can anyone help me to figure it out.
Following are my source and code behind codes.
My design Source :
<div class="field">
<asp:TextBox ID="txtareaOfferDesc" runat="server" TextMode="MultiLine" ></asp:TextBox>
</div>
<div class="field">
<asp:TextBox ID="txtTimeStarts" runat="server" CssClass="textfield"></asp:TextBox>
<cc1:CalendarExtender
ID="CalendarExtender2"
runat="server"
TargetControlID="txtTimeStarts"
CssClass="CalendarCSS">
</cc1:CalendarExtender>
<div class="datefld">
<label class="name">Offer end date/time (optional)</label>
<div class="field">
<asp:TextBox ID="txtTimeEnd" runat="server" CssClass="textfield"></asp:TextBox>
<cc1:CalendarExtender ID="CalendarExtender4" runat="server" TargetControlID="txtTimeEnd"
CssClass="CalendarCSS">
</cc1:CalendarExtender> `
<asp:GridView ID="gvShopDeal" runat="server" AutoGenerateColumns="false"
CssClass="tblexistoffer" DataKeyNames="ShopID" AllowPaging="True"
AllowSorting="True">
<Columns>
<asp:TemplateField>
<HeaderTemplate >
<asp:CheckBox ID="chkHeader" runat="server" />
<asp:Label ID="lblSelectAll" Text="Select All" runat="server"></asp:Label>
</HeaderTemplate>
<ItemTemplate >
<asp:CheckBox ID="chkRow" runat="server" />
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="ShopID" HeaderStyle-Width="10%" HeaderText="Shop ID" />
<asp:BoundField DataField="ShopName" HeaderStyle-Width="40%" HeaderText="Shop Name" />
<asp:BoundField DataField="Street" HeaderStyle-Width="40%" HeaderText="Street" />
<asp:BoundField DataField="City" HeaderText ="City" />
</Columns>
</asp:GridView>
<asp:Button ID="btnCreateDeal" runat="server" Text="Create Offer"
CssClass="grnbtn" OnClientClick="return CheckDealValidation(this)" onclick="btnCreateDeal_Click"></asp:Button>
<asp:Button ID="btnDefCancel" runat="server" Text="Cancel" CssClass="greybtn"></asp:Button>
<asp:UpdatePanel ID="UpdateExistingOffer" runat="server">
<ContentTemplate>
<asp:GridView ID="gvExistingOffers" runat="server" CssClass="tblexistoffer"
AutoGenerateColumns="false" DataKeyNames="OfferID" AllowPaging="True"
AllowSorting="True">
<Columns>
<asp:BoundField DataField="OfferID" HeaderText="OfferID" />
<asp:BoundField DataField="Description" HeaderText="OfferName" />
<asp:BoundField DataField="Status" HeaderText="Status" />
<asp:BoundField DataField="OfferType" HeaderText="OfferType" />
<asp:BoundField DataField="StartDate" HeaderText="StartDate">
<ItemStyle CssClass="Hide" />
<HeaderStyle CssClass="Hide" />
</asp:BoundField>
<asp:BoundField DataField="EndDate" HeaderText="EndDate" >
<ItemStyle CssClass="Hide" />
<HeaderStyle CssClass="Hide" />
</asp:BoundField>
<asp:TemplateField HeaderText="Edit" HeaderStyle-Width="5%">
<ItemTemplate>
<asp:ImageButton ID="imgbtnEdit" ImageUrl="~/Merchant/images/edit.jpg" runat="server" Width="25" Height="25" onclick="imgbtnEdit_Click" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</ContentTemplate>
</asp:UpdatePanel>
Code Behind File :
protected void imgbtnEdit_Click(object sender, ImageClickEventArgs e)
{
ImageButton btndetails = sender as ImageButton;
GridViewRow gvrow = (GridViewRow)btndetails.NamingContainer;
fferIDForShop = Convert.ToInt32(gvExistingOffers.DataKeys[gvrow.RowIndex].Value);
ShopList objShopID = ShopService.GetShopID(OfferIDForShop);
(txtareaOfferDesc.Text) = gvrow.Cells[1].Text.Trim();
txtTimeStarts.Text = gvrow.Cells[4].Text;
txtTimeEnd.Text = gvrow.Cells[5].Text;
}
Thanks
Vijay
Issue is because textboxes are out of Update Panel, So just put everything in update panel it will start functioning or just comment out update panel and then try the same thing.

'ASP.default_aspx' does not contain a definition for 'DS_Filtering' and no extension method

I'm getting the error below after enabling SqlDataSource filtering event on default.aspx.
'ASP.default_aspx' does not contain a
definition for 'DS_Filtering' and no
extension method
Am i missing anything?
Please help
Below might give you idea how this works, please check:
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>ASP.NET Example</title>
</head>
<body>
<form id="FORM1" runat="server">
<p>Show all employees with the following title:
<asp:DropDownList
id="DropDownList1"
runat="server"
AutoPostBack="True">
<asp:ListItem>Sales Representative</asp:ListItem>
<asp:ListItem>Sales Manager</asp:ListItem>
<asp:ListItem>Vice President, Sales</asp:ListItem>
</asp:DropDownList></p>
<asp:SqlDataSource
id="SqlDataSource1"
runat="server"
ConnectionString="<%$ ConnectionStrings:NorthwindConnection %>"
SelectCommand="SELECT EmployeeID,FirstName,LastName,Title FROM Employees"
FilterExpression="Title='{0}'" OnFiltering="SqlDataSource1_Filtering">
<FilterParameters>
<asp:ControlParameter Name="Title" ControlId="DropDownList1" PropertyName="SelectedValue"/>
</FilterParameters>
</asp:SqlDataSource><br />
<asp:GridView
id="GridView1"
runat="server"
DataSourceID="SqlDataSource1"
AutoGenerateColumns="False">
<columns>
<asp:BoundField Visible="False" DataField="EmployeeID" />
<asp:BoundField HeaderText="First Name" DataField="FirstName" />
<asp:BoundField HeaderText="Last Name" DataField="LastName" />
</columns>
</asp:GridView>
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
</form>
</body>
</html>
Server Side:
protected void SqlDataSource1_Filtering(object sender, SqlDataSourceFilteringEventArgs e)
{
Label1.Text = e.ParameterValues[0].ToString();
}

DataGrid showing in the design window, but not in the webpage

I've just started learning ASP.net and I can't seem to get the GridView to correctly show itself when I compile it. Using Visual Studio '08 in the design view, it shows it just fine, but when I compile, it's absent.
<%# Page Language="vb" AutoEventWireup="false" CodeBehind="Default.aspx.vb" Inherits="WebAppTest._Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form runat="server">
<div>
<asp:GridView id ="gridview1" runat ="server" AutoGenerateColumns = "False" BackColor="White" BorderColor="#CCCCCC" BorderStyle="None" BorderWidth="1px" CellPadding="3" >
<RowStyle ForeColor="#000066" />
<Columns>
<asp:BoundField HeaderText="Test1" />
<asp:BoundField HeaderText="Test2" />
<asp:TemplateField HeaderText="Pick one">
<ItemTemplate>
<asp:RadioButton ID="rbut1" runat="server" GroupName="test"/>
</ItemTemplate>
<ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" />
</asp:TemplateField>
</Columns>
<FooterStyle BackColor="White" ForeColor="#000066" />
<PagerStyle BackColor="White" ForeColor="#000066" HorizontalAlign="Left" />
<SelectedRowStyle BackColor="#669999" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#006699" Font-Bold="True" ForeColor="White" />
</asp:GridView>
</div>
</form>
</body>
</html>
Are you binding any data at all to the Grid? Just populate it with some data.
If there is no data nothing would show up. So, if you are using some database...like MS-SQL server...use the properties of the Grid...use the DataBinding functionality and just link it up with some table.
Now, after you compile your grid will show up with all the contents of the table in the DB ..with respective headers.
I don't see your datasouce, if you assigning it in the code-behind - you need to DataBind() the grid to see it on the page.
You can also create a datasource in the design view, and assign it to the grid - no explicit databinding needed
Have you set the datasource for the gridview?
If yes then post the code where u r binding the gridview.
Please make sure you bind the gridview with datasource.
The Grid is showing everything you have bound to it, and nothing more.

Resources