TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
sandeepkumar sangshetty
NA
9
0
Unable to find checkbox control in Gridview
Apr 21 2010 1:27 AM
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.cs
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(labelProduct ID.Text), cartID, connection);
}
}
if (textBoxCount.Text.Trim() == "")
{
ShoppingCart.RemoveFromCart(int.Parse(labelProduct ID.Text), cartID, connection);
}
}
}
}
}
Attachment:
OnlineShopping.rar
Reply
Answers (
3
)
How to create forum
Usually buttons are used to cause validation but I want to use table column to cause validation