I had the following code working perfectly to respond to the Click of an "Add to Order" button in a GridView.
I have now reused the code in a different site but am having a problem. I think it is probably related to the fact that the GridView, on the new site, is nested inside a ListView.
Looking at your quote of "gvTakeaways", you may be analysing the code from the old site which works fine. Just to check, I don't want to waste anybody's time...
I have the OnRowCreated in the mark up for the GridView so it "should" fire but I can't debug it as the page won't build: I get the same error as I stated above: "listProductsGridView' does not exist in the current context"
listProductsGridView is the name of the GridView inside the ListView. As you can see from the code posted at first, the GridView is there in the mark up. Or have I missed your point?
I really think it's a container issue. I need to add code to say "Access the button which is inside the row which is inside the GridView
which is inside the ListView"
banksidepoet
Participant
774 Points
862 Posts
Problem with Scope - GridView nested inside ListView
Jun 27, 2012 02:09 PM|LINK
Hi.
I had the following code working perfectly to respond to the Click of an "Add to Order" button in a GridView.
I have now reused the code in a different site but am having a problem. I think it is probably related to the fact that the GridView, on the new site, is nested inside a ListView.
Here's the original code:
CODEBEHIND
protected void gvTakeaways_RowCommand(object sender, GridViewCommandEventArgs e) { int currentRowIndex = Convert.ToInt32(e.CommandArgument); GridViewRow row = gvTakeaways.Rows[currentRowIndex]; string MealTitle = (string)gvTakeaways.DataKeys[currentRowIndex].Values[1]; string MealDescription = (string)gvTakeaways.DataKeys[currentRowIndex].Values[2]; double MealPrice = (double)gvTakeaways.DataKeys[currentRowIndex].Values[3]; DropDownList ddl = row.FindControl("DropDownList1") as DropDownList; string myValString = ddl.SelectedValue.ToString(); double myVal = Convert.ToDouble(myValString); double MealValue = myVal * MealPrice; String guidString; guidString = Membership.GetUser().ProviderUserKey.ToString(); Guid guidStringUser = new Guid(guidString); string connectionString = WebConfigurationManager.ConnectionStrings["*****"].ConnectionString; using (SqlConnection conn = new SqlConnection(connectionString)) { conn.Open(); SqlCommand cmd = new SqlCommand("InsertOrder", conn); cmd.CommandType = System.Data.CommandType.StoredProcedure; cmd.Parameters.Add("@UserId", SqlDbType.UniqueIdentifier); cmd.Parameters[0].Value = guidStringUser; cmd.Parameters.Add("@SessionId", SqlDbType.NVarChar); cmd.Parameters[1].Value = Session["ID"]; cmd.Parameters.Add("@Date", SqlDbType.DateTime); cmd.Parameters[2].Value = Session["Date"]; cmd.Parameters.Add("@OrderMealTitle", SqlDbType.NVarChar); cmd.Parameters[3].Value = MealTitle; cmd.Parameters.Add("@OrderMealDescription", SqlDbType.NVarChar); cmd.Parameters[4].Value = MealDescription; cmd.Parameters.Add("@OrderMealNumber", SqlDbType.Float); cmd.Parameters[5].Value = myVal; cmd.Parameters.Add("@OrderMealPrice", SqlDbType.Float); cmd.Parameters[6].Value = MealPrice; cmd.Parameters.Add("@OrderMealValue", SqlDbType.Float); cmd.Parameters[7].Value = MealValue; cmd.ExecuteNonQuery(); conn.Close(); } }And here's the GridView
<asp:GridView ID="gvTakeaways" runat="server" AutoGenerateColumns="False" DataSourceID="takeawayDataSource" DataKeyNames="MealID,MealTitle,MealDescription,MealPrice" BorderStyle="None" EmptyDataText="There are no meals in this category." GridLines="None" OnRowCommand="gvTakeaways_RowCommand"> <AlternatingRowStyle CssClass="gvAlternateRow" /> <Columns> <asp:BoundField DataField="MealTitle" SortExpression="MealTitle"> <ItemStyle CssClass="gvMealTitle" /> </asp:BoundField> <asp:BoundField DataField="MealDescription" SortExpression="MealDescription"> <ItemStyle CssClass="gvMealDescription" /> </asp:BoundField> <asp:BoundField DataField="MealPrice" HeaderText="Price" SortExpression="MealPrice" DataFormatString="{0:C2}"> <ItemStyle CssClass="gvMealPrice" /> </asp:BoundField> <asp:TemplateField HeaderText="How Many?"> <ItemTemplate> <asp:DropDownList ID="DropDownList1" runat="server"> <asp:ListItem>1</asp:ListItem> <asp:ListItem>2</asp:ListItem> <asp:ListItem>3</asp:ListItem> <asp:ListItem>4</asp:ListItem> <asp:ListItem>5</asp:ListItem> <asp:ListItem>6</asp:ListItem> <asp:ListItem>7</asp:ListItem> <asp:ListItem>8</asp:ListItem> <asp:ListItem>9</asp:ListItem> <asp:ListItem>10</asp:ListItem> </asp:DropDownList> </ItemTemplate> <ItemStyle CssClass="gvMealNumber" /> </asp:TemplateField> <asp:ButtonField ButtonType="Button" Text="Add"> <ControlStyle CssClass="gvButtonControl" /> <ItemStyle CssClass="gvButton" /> </asp:ButtonField> </Columns> <HeaderStyle CssClass="gvHeader" /> <RowStyle CssClass="gvRow" /> </asp:GridView>Towards the bottom of the GridView markup, there is a ButtonField. This is the button handled by the RowCommand in the Code Behind.
Right... that works fine. Here is the new code, inside a ListView...
CodeBehind (up to error)
protected void listProductsGridView_RowCommand(object sender, GridViewCommandEventArgs e) { int currentRowIndex = Convert.ToInt32(e.CommandArgument); GridViewRow row = listProductsGridView.Rows[currentRowIndex];...
And the GridView
<asp:GridView ID="listProductsGridView" runat="server" AutoGenerateColumns="False" DataSourceID="getSubSectorHeadingsSqlDataSource" Width="500px" CssClass="productGV" BorderStyle="Solid" BorderWidth="1px" BorderColor="#CCCCCC" AlternatingRowStyle-BackColor="#FAFAFA" GridLines="Both" AlternatingRowStyle-CssClass="ARStyle" ForeColor="#505050" HeaderStyle-BackColor="#EEEEEE" HeaderStyle-ForeColor="#1E5E9F" HorizontalAlign="Center" HeaderStyle-HorizontalAlign="Center" HeaderStyle-VerticalAlign="Middle" HeaderStyle-Height="30px" HeaderStyle-CssClass="prodGVHeader" CellPadding="4" RowStyle-BorderStyle="Solid" RowStyle-BorderWidth="1px" RowStyle-BorderColor="#CCCCCC" RowStyle-Height="50px" DataKeyNames="product_id" OnRowCommand="listProductsGridView_RowCommand"> <AlternatingRowStyle BackColor="#FAFAFA" CssClass="ARStyle"></AlternatingRowStyle> <Columns> <asp:BoundField DataField="reference" HeaderText="Code" SortExpression="reference" ItemStyle-HorizontalAlign="Center" ItemStyle-VerticalAlign="Middle" ItemStyle-Height="25px" ItemStyle-Width="70px"> <ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" Height="25px" Width="120px" CssClass="prodGVItemStyle"></ItemStyle> </asp:BoundField> <asp:TemplateField HeaderText="Product" SortExpression="title"> <ItemTemplate> <asp:HyperLink ID="HyperLink5" runat="server" Text='<%# Eval("name") + " " + Eval("title") %>' NavigateUrl='<%# string.Format("/accessories-19/in-sight-micro-accessories-20/product-detail.aspx?product_id={0}&category_id={1}", Eval("product_id"), Eval("category_id")) %>'></asp:HyperLink> </ItemTemplate> <ItemStyle CssClass="prodGVProd prodGVItemStyle" ForeColor="#1E5E9F" Height="25px" HorizontalAlign="Center" VerticalAlign="Middle" Width="160px" /> </asp:TemplateField> <asp:TemplateField HeaderText="Price"> <ItemTemplate> <asp:Label ID="Label1" runat="server" Text="P.O.A." Width="60px"></asp:Label> </ItemTemplate> <ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" CssClass="prodGVItemStyle" /> </asp:TemplateField> <asp:TemplateField HeaderText="Quantity"> <ItemTemplate> <asp:TextBox ID="TextBox1" runat="server" Width="30px" CssClass="prodGVTextBox" Text="0"></asp:TextBox> </ItemTemplate> <ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" Width="60px" CssClass="prodGVItemStyle" /> </asp:TemplateField> <asp:ButtonField ButtonType="Image" Text="Add to Quote" ImageUrl="~/assets/images/buttons/addtocart_small.gif" CommandName="addToQuote"> <ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" Width="100px" CssClass="prodGVItemStyle" /> </asp:ButtonField> </Columns> <HeaderStyle HorizontalAlign="Center" VerticalAlign="Middle" BackColor="#EEEEEE" CssClass="prodGVHeader" ForeColor="#003399" Height="30px"></HeaderStyle> <RowStyle BorderColor="#CCCCCC" BorderWidth="1px" BorderStyle="Solid"></RowStyle> </asp:GridView>The error I'm getting is in the Code Behind on the last line pasted above.
On this line:
GridViewRow row = listProductsGridView.Rows[currentRowIndex];
listProductGridView is underlined with the message: "The name listProductsGridView does not exist in the current context."
Anyone got any ideas where I've gone wrong. I know I haven't written any code that handles the fact that the GridView is inside a ListView.
Thanks in advance.
Rajaji.K
Member
506 Points
78 Posts
Re: Problem with Scope - GridView nested inside ListView
Jun 27, 2012 05:04 PM|LINK
I think e.CommandArgument returns the Command Argument set for the button in the grid.
If you want to use your code than on row create add the command argument to button like below
void gvTakeaways_RowCreated(Object sender, GridViewRowEventArgs e) { if(e.Row.RowType == DataControlRowType.DataRow) { Button addButton = (Button)e.Row.Cells[4].Controls[0]; addButton.CommandArgument = e.Row.RowIndex.ToString(); } }banksidepoet
Participant
774 Points
862 Posts
Re: Problem with Scope - GridView nested inside ListView
Jun 27, 2012 07:15 PM|LINK
Thanks for your response.
Looking at your quote of "gvTakeaways", you may be analysing the code from the old site which works fine. Just to check, I don't want to waste anybody's time...
I've added the following:
protected void listProductsGridView_RowCreated(Object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow) { Button addButton = (Button)e.Row.Cells[4].Controls[0]; addButton.CommandArgument = e.Row.RowIndex.ToString(); } }to the Code Behind but it has no effect on the error.
Rajaji.K
Member
506 Points
78 Posts
Re: Problem with Scope - GridView nested inside ListView
Jun 28, 2012 02:39 AM|LINK
Is the above event is firing while creating rows ?
If above event is firing than debug and check whether debugger is moving inside if condition or not and also below control is button or not.
banksidepoet
Participant
774 Points
862 Posts
Re: Problem with Scope - GridView nested inside ListView
Jun 28, 2012 07:04 AM|LINK
I have the OnRowCreated in the mark up for the GridView so it "should" fire but I can't debug it as the page won't build: I get the same error as I stated above: "listProductsGridView' does not exist in the current context"
Rajaji.K
Member
506 Points
78 Posts
Re: Problem with Scope - GridView nested inside ListView
Jun 28, 2012 07:12 AM|LINK
Check whether listProductsGridView is there in designer.cs or not
banksidepoet
Participant
774 Points
862 Posts
Re: Problem with Scope - GridView nested inside ListView
Jun 28, 2012 09:23 AM|LINK
listProductsGridView is the name of the GridView inside the ListView. As you can see from the code posted at first, the GridView is there in the mark up. Or have I missed your point?
I really think it's a container issue. I need to add code to say "Access the button which is inside the row which is inside the GridView which is inside the ListView"
Rajaji.K
Member
506 Points
78 Posts
Re: Problem with Scope - GridView nested inside ListView
Jun 28, 2012 09:40 AM|LINK
How you are binding data to GridView, which is inside ListView.
banksidepoet
Participant
774 Points
862 Posts
Re: Problem with Scope - GridView nested inside ListView
Jun 28, 2012 09:52 AM|LINK
Here's the full code:
Mark Up
<%@ Page Title="" Language="C#" MasterPageFile="~/master-pages/accessories.master" AutoEventWireup="true" CodeFile="in-sight-micro-accessories-20.aspx.cs" Inherits="accessories_19_in_sight_micro_accessories_20" %> <asp:Content ID="Content1" ContentPlaceHolderID="head" runat="Server"> </asp:Content> <asp:Content ID="Content2" ContentPlaceHolderID="Main" runat="Server"> <div id="catHeadBorder"> <div id="catHead"> <asp:Label ID="categoryTitleLabel" runat="server"></asp:Label></div> <p class="sectionHead"> <a href="/Default.aspx">Home</a> > <a href="/accessories-19.aspx">Accessories</a> > <asp:Label ID="categoryBCLabel" runat="server"></asp:Label></p> <div id="categoryDescriptionPane"> <asp:Label ID="dynamicSectionDescription" runat="server"></asp:Label> </div> <div id="catFilters"> <asp:DropDownList ID="manufacturerDropDownList" runat="server" CssClass="catDDL" AutoPostBack="True" OnSelectedIndexChanged="manufacturerDropDownList_SelectedIndexChanged"> <asp:ListItem Value="0">Manufacturer</asp:ListItem> <asp:ListItem Value="4">CCS</asp:ListItem> <asp:ListItem Value="3">Cognex</asp:ListItem> </asp:DropDownList> <%--<asp:DropDownList ID="prodGroupDropDownList" runat="server" CssClass="catDDLLong" AutoPostBack="True" OnSelectedIndexChanged="prodGroupDropDownList_SelectedIndexChanged"> <asp:ListItem Value="/accessories-19.aspx">Accessories</asp:ListItem> <asp:ListItem Selected="True" Value="/accessories-19/in-sight-micro-accessories-20.aspx">- In-Sight Micro Accessories</asp:ListItem> <asp:ListItem Value="/accessories-19/in-sight-micro-accessories-20/cables-60.aspx">- - Cables</asp:ListItem> <asp:ListItem Value="/accessories-19/in-sight-micro-accessories-20/warranties-firmware-upgrades-61.aspx">- - Warranties & Firmware Upgrades</asp:ListItem> <asp:ListItem Value="/accessories-19/in-sight-micro-accessories-20/power-supplies-62.aspx">- - Power Supplies</asp:ListItem> <asp:ListItem Value="/accessories-19/in-sight-micro-accessories-20/i-o-modules-63.aspx">- - I/O Modules</asp:ListItem> <asp:ListItem Value="/accessories-19/in-sight-micro-accessories-20/manuals-88.aspx">- - Manuals</asp:ListItem> <asp:ListItem Value="/accessories-19/in-sight-micro-accessories-20/operator-interfaces-89.aspx">- - Operator Interfaces</asp:ListItem> <asp:ListItem Value="/accessories-19/in-sight-micro-accessories-20/led-lights-92.aspx">- - LED Lights</asp:ListItem> <asp:ListItem Value="/accessories-19/in-sight-micro-accessories-20/brackets-enclosures-93.aspx">- - Brackets & Enclosures</asp:ListItem> <asp:ListItem Value="/accessories-19/in-sight-micro-accessories-20/other-accessories-100.aspx">- - Other Accessories</asp:ListItem> </asp:DropDownList>--%> </div> </div> <div id="centreTextArea"> <asp:Label ID="manufacturerWhereClause" runat="server" Visible="False"></asp:Label> <asp:SqlDataSource ID="getMainSectorHeadingsSqlDataSource" runat="server" ConnectionString="<%$ ConnectionStrings:***** %>" SelectCommand="SELECT DISTINCT categories.category_id, categories.name, categories.sort_order FROM categories INNER JOIN products_to_categories ON categories.category_id = products_to_categories.category_id INNER JOIN products ON products_to_categories.product_id = products.product_id INNER JOIN manufacturers ON products.manufacturer_id = manufacturers.manufacturer_id WHERE (categories.active = @active) AND (categories.parent_id = @parent_id) AND (manufacturers.name LIKE @manufacturer) ORDER BY categories.sort_order"> <SelectParameters> <asp:Parameter DefaultValue="Y" Name="active" Type="String" /> <asp:Parameter DefaultValue="20" Name="parent_id" Type="Int32" /> <asp:ControlParameter ControlID="manufacturerWhereClause" DefaultValue="" Name="manufacturer" PropertyName="Text" Type="String" /> </SelectParameters> </asp:SqlDataSource> <asp:ListView ID="displayMainSectorHeadingsListView" runat="server" DataKeyNames="category_id" DataSourceID="getMainSectorHeadingsSqlDataSource"> <EmptyDataTemplate> No data was returned.</EmptyDataTemplate> <ItemSeparatorTemplate> <br /> </ItemSeparatorTemplate> <ItemTemplate> <li style="font-size: 12px; color: rgb(30, 94, 159); font-weight: bold; margin-top: 20px"> <asp:Label ID="categoryIdLabel" runat="server" Text='<%# Eval("category_id") %>' Visible="False" /> <asp:Label ID="nameLabel" runat="server" Text='<%# Eval("name") %>' /> <br /> <br /> <asp:SqlDataSource ID="getSubSectorHeadingsSqlDataSource" runat="server" ConnectionString="<%$ ConnectionStrings:***** %>" SelectCommand="SELECT DISTINCT products.product_id, products.title, products.seo_name, products.summary, products.reference, products.active, manufacturers.name, categories.category_id FROM products_to_categories INNER JOIN products ON products_to_categories.product_id = products.product_id INNER JOIN categories ON products_to_categories.category_id = categories.category_id INNER JOIN manufacturers ON products.manufacturer_id = manufacturers.manufacturer_id WHERE (products.active = @active) AND (manufacturers.name LIKE @manufacturer) AND (categories.category_id = @categoryID)"> <SelectParameters> <asp:Parameter DefaultValue="Y" Name="active" Type="String" /> <asp:ControlParameter ControlID="manufacturerWhereClause" DefaultValue="" Name="manufacturer" PropertyName="Text" Type="String" /> <asp:ControlParameter ControlID="categoryIDLabel" DefaultValue="" Name="categoryID" PropertyName="Text" Type="String" /> </SelectParameters> </asp:SqlDataSource> <asp:GridView ID="listProductsGridView" runat="server" AutoGenerateColumns="False" DataSourceID="getSubSectorHeadingsSqlDataSource" Width="500px" CssClass="productGV" BorderStyle="Solid" BorderWidth="1px" BorderColor="#CCCCCC" AlternatingRowStyle-BackColor="#FAFAFA" GridLines="Both" AlternatingRowStyle-CssClass="ARStyle" ForeColor="#505050" HeaderStyle-BackColor="#EEEEEE" HeaderStyle-ForeColor="#1E5E9F" HorizontalAlign="Center" HeaderStyle-HorizontalAlign="Center" HeaderStyle-VerticalAlign="Middle" HeaderStyle-Height="30px" HeaderStyle-CssClass="prodGVHeader" CellPadding="4" RowStyle-BorderStyle="Solid" RowStyle-BorderWidth="1px" RowStyle-BorderColor="#CCCCCC" RowStyle-Height="50px" DataKeyNames="product_id" OnRowCommand="listProductsGridView_RowCommand" OnRowCreated="listProductsGridView_RowCreated"> <AlternatingRowStyle BackColor="#FAFAFA" CssClass="ARStyle"></AlternatingRowStyle> <Columns> <asp:BoundField DataField="reference" HeaderText="Code" SortExpression="reference" ItemStyle-HorizontalAlign="Center" ItemStyle-VerticalAlign="Middle" ItemStyle-Height="25px" ItemStyle-Width="70px"> <ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" Height="25px" Width="120px" CssClass="prodGVItemStyle"></ItemStyle> </asp:BoundField> <asp:TemplateField HeaderText="Product" SortExpression="title"> <ItemTemplate> <asp:HyperLink ID="HyperLink5" runat="server" Text='<%# Eval("name") + " " + Eval("title") %>' NavigateUrl='<%# string.Format("/accessories-19/in-sight-micro-accessories-20/product-detail.aspx?product_id={0}&category_id={1}", Eval("product_id"), Eval("category_id")) %>'></asp:HyperLink> </ItemTemplate> <ItemStyle CssClass="prodGVProd prodGVItemStyle" ForeColor="#1E5E9F" Height="25px" HorizontalAlign="Center" VerticalAlign="Middle" Width="160px" /> </asp:TemplateField> <asp:TemplateField HeaderText="Price"> <ItemTemplate> <asp:Label ID="Label1" runat="server" Text="P.O.A." Width="60px"></asp:Label> </ItemTemplate> <ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" CssClass="prodGVItemStyle" /> </asp:TemplateField> <asp:TemplateField HeaderText="Quantity"> <ItemTemplate> <asp:TextBox ID="TextBox1" runat="server" Width="30px" CssClass="prodGVTextBox" Text="0"></asp:TextBox> </ItemTemplate> <ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" Width="60px" CssClass="prodGVItemStyle" /> </asp:TemplateField> <asp:ButtonField ButtonType="Image" Text="Add to Quote" ImageUrl="~/assets/images/buttons/addtocart_small.gif" CommandName="addToQuote"> <ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" Width="100px" CssClass="prodGVItemStyle" /> </asp:ButtonField> </Columns> <HeaderStyle HorizontalAlign="Center" VerticalAlign="Middle" BackColor="#EEEEEE" CssClass="prodGVHeader" ForeColor="#003399" Height="30px"></HeaderStyle> <RowStyle BorderColor="#CCCCCC" BorderWidth="1px" BorderStyle="Solid"></RowStyle> </asp:GridView> </li> </ItemTemplate> <LayoutTemplate> <ul id="itemPlaceholderContainer" runat="server" style="list-style: none;"> <li runat="server" id="itemPlaceholder" /> </ul> <div style=""> </div> </LayoutTemplate> </asp:ListView> </div> </asp:Content>Code Behind
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Data; using System.Data.SqlClient; using System.Web.Security; using System.Web.Configuration; public partial class accessories_19_in_sight_micro_accessories_20 : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { // On first load, set Session "ID" and "Date" as this page contains an "Add to Quote" button Session["ID"] = Session.SessionID; Session["Date"] = DateTime.Now; // On first load, set selected item in DDL via query string if (!Page.IsPostBack) { manufacturerDropDownList.Items.FindByValue(Request.QueryString["man_id"]).Selected = true; } if (manufacturerDropDownList.SelectedValue == "0") { manufacturerWhereClause.Text = "%"; } else { manufacturerWhereClause.Text = manufacturerDropDownList.SelectedItem.Text; } // Identify this webpage int webpage_id = 20; //Connection String string connectionString = WebConfigurationManager.ConnectionStrings["*****"].ConnectionString; SqlConnection conn = new SqlConnection(connectionString); // Build SQL Command 1 (Description Box) SqlCommand cmd1; string commandString1 = "SELECT [description] FROM categories WHERE category_id = @category_id"; cmd1 = new SqlCommand(commandString1, conn); cmd1.Parameters.AddWithValue("category_id", webpage_id); //Build SQL Command 2 (Get Page Breadcrumb and Heading) SqlCommand cmd2; string commandString2 = "SELECT [name] FROM categories WHERE category_id = @category_id"; cmd2 = new SqlCommand(commandString2, conn); cmd2.Parameters.AddWithValue("category_id", webpage_id); //Build SQL Command 3 (Get Manufacturer Name) SqlCommand cmd3; string commandString3 = "SELECT [name] FROM manufacturers WHERE manufacturer_id = @manufacturer_id"; cmd3 = new SqlCommand(commandString3, conn); cmd3.Parameters.AddWithValue("manufacturer_id", Request.QueryString["man_id"]); // Open Connection conn.Open(); // Get Description for box at top string tempText = (string)cmd1.ExecuteScalar(); // Get titles categoryTitleLabel.Text = (string)cmd3.ExecuteScalar() + " " + (string)cmd2.ExecuteScalar(); categoryBCLabel.Text = (string)cmd3.ExecuteScalar() + " " + (string)cmd2.ExecuteScalar(); Page.Title = "Accessories - " + (string)cmd3.ExecuteScalar() + " " + (string)cmd2.ExecuteScalar(); // Close Connection conn.Close(); // Assign final result to Description Box at top of page dynamicSectionDescription.Text = tempText; } protected void manufacturerDropDownList_SelectedIndexChanged(object sender, EventArgs e) { if (manufacturerDropDownList.SelectedValue == "0") { manufacturerWhereClause.Text = "%"; Response.Redirect("/accessories-19/in-sight-micro-accessories-20.aspx?man_id=" + manufacturerDropDownList.SelectedValue); } else { manufacturerWhereClause.Text = manufacturerDropDownList.SelectedItem.Text; Response.Redirect("/accessories-19/in-sight-micro-accessories-20.aspx?man_id=" + manufacturerDropDownList.SelectedValue); } } void listProductsGridView_RowCreated(Object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow) { Button addButton = (Button)e.Row.Cells[4].Controls[0]; addButton.CommandArgument = e.Row.RowIndex.ToString(); } } // AT EACH "ADD TO Quote" BUTTON CLICK... void listProductsGridView_RowCommand(object sender, GridViewCommandEventArgs e) { int currentRowIndex = Convert.ToInt32(e.CommandArgument); GridViewRow row = listProductsGridView.Rows[currentRowIndex]; } }You can see from the last line where I've underlined the point of the error.
Thanks
Rajaji.K
Member
506 Points
78 Posts
Re: Problem with Scope - GridView nested inside ListView
Jun 28, 2012 10:00 AM|LINK
bind gridview OnRowCommand and OnRowCreated events in ListView ItemDataBound Event