473,791 Members | 3,090 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Unable to find checkbox control in Gridview

12 New Member
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
Expand|Select|Wrap|Line Numbers
  1. <%@ Control Language="C#" AutoEventWireup="true" CodeFile="_BigCart.ascx.cs" Inherits="_BigCart" %>
  2. <link href="Main.css" rel="stylesheet" type="text/css" />
  3.  
  4.  
  5.        <asp:Label ID="Label3" runat="server" Text="Label"></asp:Label>
  6.  
  7.    <asp:GridView id="gridViewBigCart" Height="118px"  AutoGenerateColumns="False" runat="server" CssClass="checkout" Width="615px" DataKeyNames="Quantity" >
  8.  
  9.    <Columns>
  10.  
  11.      <asp:TemplateField HeaderText="Remove">
  12.       <ItemTemplate>
  13.           <asp:CheckBox ID="checkBoxDelete" runat="server" />
  14.       </ItemTemplate>
  15.      </asp:TemplateField>
  16.  
  17.      <asp:TemplateField HeaderText="Quantity">
  18.       <ItemTemplate>
  19.         <asp:TextBox id="textBoxQuantity" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "Quantity")%>' width="40px" Columns="4">
  20.         </asp:TextBox>
  21.       </ItemTemplate>
  22.      </asp:TemplateField>
  23.  
  24.      <asp:TemplateField Visible="False">
  25.        <ItemTemplate>
  26.          <asp:Label id="labelProductID" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "ProductID")%>' Visible="False" Width="298px">
  27.          </asp:Label>
  28.        </ItemTemplate>
  29.     </asp:TemplateField>
  30.  
  31.     <asp:BoundField DataField="ProductName" HeaderText="Product Name">
  32.     </asp:BoundField>
  33.  
  34.     <asp:BoundField DataField="QuantityPerUnit" HeaderText="Qty Per Unit">
  35.     </asp:BoundField>
  36.  
  37.     <asp:BoundField DataField="UnitPrice" HeaderText="Unit Price" DataFormatString="{0:c}">
  38.     </asp:BoundField>
  39.  
  40.     <asp:BoundField DataField="TotalDue" HeaderText="Total Due" DataFormatString="{0:c}">
  41.     </asp:BoundField>
  42.  
  43.   </Columns>
  44.  </asp:GridView>
  45.  
  46.        <asp:Button ID="Button1" runat="server" Text="Update Cart" OnClick="Button1_Click" />
  47.        <br />
  48.        <asp:Button ID="Button2" runat="server" Text="Proceed To Checkout" />
  49.        <br />
  50.        <asp:Label ID="labelTotalDue" runat="server"></asp:Label>
  51.  
  52.  
  53.        <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
  54.  
  55.  
  56.        <asp:Label ID="errorMessage" runat="server"></asp:Label>
-------------------------------------------------------------------------------

_BigCart.ascx.c s

Expand|Select|Wrap|Line Numbers
  1. using System;
  2. using System.Data;
  3. using System.Configuration;
  4. using System.Collections;
  5. using System.Web;
  6. using System.Web.Security;
  7. using System.Web.UI;
  8. using System.Web.UI.WebControls;
  9. using System.Web.UI.WebControls.WebParts;
  10. using System.Web.UI.HtmlControls;
  11. using System.Data.SqlClient;
  12.  
  13. public partial class _BigCart : System.Web.UI.UserControl
  14. {
  15.     protected void Page_Load(object sender, EventArgs e)
  16.     {
  17.         GridViewDataBind();
  18.     }
  19.     protected void GridViewDataBind()
  20.     {
  21.         string connection = ConfigurationManager.ConnectionStrings["NorthwindConnectionString"].ConnectionString.ToString();
  22.         string cartId = Request.Cookies["CartID"].Value.ToString();
  23.         if (cartId != string.Empty)
  24.         {
  25.             gridViewBigCart.DataSource = ShoppingCart.GetCart(cartId, connection);
  26.             gridViewBigCart.DataBind();
  27.             labelTotalDue.Text = "Total Order Amount: " + string.Format("{0:0.00}", ShoppingCart.GetCartSum(cartId, connection));
  28.         }
  29.     }
  30.  
  31.  
  32.  
  33.     protected void Button1_Click(object sender, EventArgs e)
  34.     {
  35.  
  36.         string cartID = Request.Cookies["CartID"].Value.ToString();
  37.         string connection = ConfigurationManager.ConnectionStrings["NorthwindConnectionString"].ConnectionString.ToString();
  38.  
  39.             foreach (GridViewRow gvRow in gridViewBigCart.Rows)
  40.             {
  41.                 if (gvRow.RowType == DataControlRowType.DataRow)
  42.                 {
  43.                     CheckBox checkBoxDelete = (CheckBox)gvRow.Cells[0].FindControl("checkBoxDelete");---(Here checkbox 'null' getting)
  44.                     Label labelProductID = (Label)gvRow.FindControl("labelProductID");
  45.                     TextBox textBoxCount = (TextBox)gvRow.FindControl("textBoxQuantity");
  46.  
  47.                     if (checkBoxDelete != null)
  48.                     {
  49.                         if (checkBoxDelete.Checked)---(checkbox 'false' getting)
  50.                         {
  51.                             ShoppingCart.RemoveFromCart(int.Parse(labelProductID.Text), cartID, connection);
  52.                         }
  53.                     }
  54.                     if (textBoxCount.Text.Trim() == "")
  55.                     {
  56.                         ShoppingCart.RemoveFromCart(int.Parse(labelProductID.Text), cartID, connection);
  57.                     }
  58.  
  59.                 }
  60.  
  61.             }
  62.  
  63.         }
  64.  
  65. }
Apr 21 '10 #1
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:

Expand|Select|Wrap|Line Numbers
  1. 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
Apr 21 '10 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

3
17116
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") %>' />
1
21472
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...
3
2532
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....
0
2760
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...
1
6135
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...
1
13909
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...
3
9010
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
1
1641
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...
0
4188
parshupooja
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...
1
2426
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...
0
9515
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,...
0
9995
tracyyun
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...
0
9029
agi2029
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...
1
7537
isladogs
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...
0
6776
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();...
0
5559
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4110
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
2
3718
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2916
bsmnconsultancy
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...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.