Hi Friends,
I'm unable find check box control in my webpage.
When building the page I'm getting "checkbox null" and "false".
Can any help me to find the solution.
I'm pasting the code here.
------------------------------------------------------------------------------- _BigCart.ascx -
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="_BigCart.ascx.cs" Inherits="_BigCart" %>
-
<link href="Main.css" rel="stylesheet" type="text/css" />
-
-
-
<asp:Label ID="Label3" runat="server" Text="Label"></asp:Label>
-
-
<asp:GridView id="gridViewBigCart" Height="118px" AutoGenerateColumns="False" runat="server" CssClass="checkout" Width="615px" DataKeyNames="Quantity" >
-
-
<Columns>
-
-
<asp:TemplateField HeaderText="Remove">
-
<ItemTemplate>
-
<asp:CheckBox ID="checkBoxDelete" runat="server" />
-
</ItemTemplate>
-
</asp:TemplateField>
-
-
<asp:TemplateField HeaderText="Quantity">
-
<ItemTemplate>
-
<asp:TextBox id="textBoxQuantity" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "Quantity")%>' width="40px" Columns="4">
-
</asp:TextBox>
-
</ItemTemplate>
-
</asp:TemplateField>
-
-
<asp:TemplateField Visible="False">
-
<ItemTemplate>
-
<asp:Label id="labelProductID" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "ProductID")%>' Visible="False" Width="298px">
-
</asp:Label>
-
</ItemTemplate>
-
</asp:TemplateField>
-
-
<asp:BoundField DataField="ProductName" HeaderText="Product Name">
-
</asp:BoundField>
-
-
<asp:BoundField DataField="QuantityPerUnit" HeaderText="Qty Per Unit">
-
</asp:BoundField>
-
-
<asp:BoundField DataField="UnitPrice" HeaderText="Unit Price" DataFormatString="{0:c}">
-
</asp:BoundField>
-
-
<asp:BoundField DataField="TotalDue" HeaderText="Total Due" DataFormatString="{0:c}">
-
</asp:BoundField>
-
-
</Columns>
-
</asp:GridView>
-
-
<asp:Button ID="Button1" runat="server" Text="Update Cart" OnClick="Button1_Click" />
-
<br />
-
<asp:Button ID="Button2" runat="server" Text="Proceed To Checkout" />
-
<br />
-
<asp:Label ID="labelTotalDue" runat="server"></asp:Label>
-
-
-
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
-
-
-
<asp:Label ID="errorMessage" runat="server"></asp:Label>
------------------------------------------------------------------------------- _BigCart.ascx.c s -
using System;
-
using System.Data;
-
using System.Configuration;
-
using System.Collections;
-
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 System.Data.SqlClient;
-
-
public partial class _BigCart : System.Web.UI.UserControl
-
{
-
protected void Page_Load(object sender, EventArgs e)
-
{
-
GridViewDataBind();
-
}
-
protected void GridViewDataBind()
-
{
-
string connection = ConfigurationManager.ConnectionStrings["NorthwindConnectionString"].ConnectionString.ToString();
-
string cartId = Request.Cookies["CartID"].Value.ToString();
-
if (cartId != string.Empty)
-
{
-
gridViewBigCart.DataSource = ShoppingCart.GetCart(cartId, connection);
-
gridViewBigCart.DataBind();
-
labelTotalDue.Text = "Total Order Amount: " + string.Format("{0:0.00}", ShoppingCart.GetCartSum(cartId, connection));
-
}
-
}
-
-
-
-
protected void Button1_Click(object sender, EventArgs e)
-
{
-
-
string cartID = Request.Cookies["CartID"].Value.ToString();
-
string connection = ConfigurationManager.ConnectionStrings["NorthwindConnectionString"].ConnectionString.ToString();
-
-
foreach (GridViewRow gvRow in gridViewBigCart.Rows)
-
{
-
if (gvRow.RowType == DataControlRowType.DataRow)
-
{
-
CheckBox checkBoxDelete = (CheckBox)gvRow.Cells[0].FindControl("checkBoxDelete");---(Here checkbox 'null' getting)
-
Label labelProductID = (Label)gvRow.FindControl("labelProductID");
-
TextBox textBoxCount = (TextBox)gvRow.FindControl("textBoxQuantity");
-
-
if (checkBoxDelete != null)
-
{
-
if (checkBoxDelete.Checked)---(checkbox 'false' getting)
-
{
-
ShoppingCart.RemoveFromCart(int.Parse(labelProductID.Text), cartID, connection);
-
}
-
}
-
if (textBoxCount.Text.Trim() == "")
-
{
-
ShoppingCart.RemoveFromCart(int.Parse(labelProductID.Text), cartID, connection);
-
}
-
-
}
-
-
}
-
-
}
-
-
}
1 5560 Frinavale 9,735
Recognized Expert Moderator Expert
On line 43 in the above post code for the _BigCart.ascx.c s file you have are using the FindControl on Cell[0]. Instead of using the FindControl method on Cell[0], use it on the GridViewRow: -
CheckBox checkBoxDelete = (CheckBox)gvRow.FindControl("checkBoxDelete");
In the future please post your code in code tags. It makes it easier for us to read your code and it provides us with line numbers that we can refer back to when helping you.
Also, please don't post Everything...ju st post the code that is relevant to the question (like the GridView markup for the column containing the CheckBox...and the function where you are having problems retrieving it in your C# code). It just makes it easier for us to help you if we don't have to scan through everything to find the line that's causing the problem (at least you were kind enough to point out the line using comments..thank s!)
-Frinny
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Dabbler |
last post by:
I have a checkbox control in a GridView EditItemTemplate. My SqlDataAdapter
complains when I try and use UpdateCommand
Thanks on any binding clarification.
GridView:
<asp:TemplateField HeaderText="Active">
<ItemTemplate>
<asp:CheckBox ID="ActiveCheckBox" runat="server" Checked='<%#
Eval("Active") %>' />
|
by: mercercreek |
last post by:
This one should be easy. Hope someone has a clue.
Simple Scenario: Gridview with mulitple rows, each row with a checkbox.
The user checks boxes of her choice. Clicks a button on the form (not
in the grid). Desired aciton is then taken in response to the
button_onclick event relevant to the row in which the checked
checkboxes exist.
Unfortunate Outcome: Each checkbox returns false for its
attribute:checked whether the user has placed a...
|
by: =?Utf-8?B?QnJldA==?= |
last post by:
I am a VB Developer w/ SQL Server experience breaking into web world via the
Visual Web Developer Express. I've already set up my data sources to my SQL
Server tables and have created a grid view of my tables which executes
successfully. Two of the fields in the gridview are checkboxes that are
bound to a table, datatype is "bit". These 2 fields are "APPROVED" or
"DENIED", in other words, the user needs to check approve or deny a record....
|
by: ballamber |
last post by:
This is a solution to the problem. Works with .NET 2.0.
So the problem is displaying a data bound read-only checkbox or radio button in a GridView without actually disabling those controls.
I assume you know what templates are in a GridView. Examples are in VB.NET. Sorry...
So as a first step create a function in the page's underlying class that returns the string "checked" based on the bound data. Here's what I did. The underlying data...
|
by: sheenaa |
last post by:
Hello Members,
I m creating my application forms in ASP.Net 2005 C# using the backend SQL Server 2005.
What i have used on forms :: ?
On my first form i have used some label,textboxs,dropdownlists,radiobutton and checkbox asp standard controls.
On the click event of the command button the data gets stored into the database.
I have created the stored procedures for the insert,update,delete.
I have...
| |
by: dhamo |
last post by:
How to bind checkbox with gridview in asp.net 2.0
I take a gridview control and bind data dynamicaly using code.I taken backend tool as a Ms Access and now I want to add new column with checkbox so user can delete selected recored..So How can I bind checkbox with gridview...
|
by: =?Utf-8?B?Um9iZXJ0IFNtaXRo?= |
last post by:
Hi,
I have a GridView with a checkbox column in it called FromInsight,
however this
is not bound to the dataset, its value is based on another column from the
dataset called sourceid
For each row FromInsight = true if (SourceId 0). I try to loop around the
gridview and add the value of the checkbox but the column seems to have no
checked value, please can you help with this.
Thanx in advance
Robert
|
by: mani.shanku |
last post by:
hi friendsplz..help me its urgent.....
im making a jobportal site..when a person go for search the results
should desplay....
like the naukri.com desplays..and when a person click on the checkbox
box link...
it is navigating to another window..
......my problem is .i added a checkbox control to gridview but i can't
able to make navigation when he clicks on that checkbox
plz..help me...
|
by: parshupooja |
last post by:
Hey All,
I have where I want to do some manipulations and show in other column but unable to find their values in RowDatabound event even though I have two records in gridview
<asp:GridView ID="GridView1" runat="server" ShowFooter="True" AutoGenerateColumns="false" Width="700px">
<Columns>
<asp:TemplateField HeaderText="Qty">
<EditItemTemplate>
<asp:TextBox...
|
by: abhi83 |
last post by:
Hi ,
I have a problem hope someone can help.
I have created a dynamic view which contains a gridview. This gridview contains a check box column in the Template Field with the help of ITemplate interface.
Now the prblm is I'm not able to access this check box . I am using
CheckBox chkSel = (CheckBox)gvRows.Cells.FindControl("ckh");
to find the check box but 'chkSel' is always returning null.This check box is in every row of the...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |