473,396 Members | 1,998 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

CheckBox in DataGrid

Hi.

This little thing is killing me. I have CheckBoxes in a DataGrid as below.
When user pushes a submit button, I want to know what CheckBoxes are checked.
However, in the submit button handler, I can't seem to get the state of
these CheckBoxes.

When I do if (oCheckBox.Checked == true) in C# code, my CheckBoxes are not
checked even though I check them.

Please help.

<Columns>
<asp:TemplateColumn HeaderText="Appointment Date">
<itemtemplate>
<%# DataBinder.Eval(Container.DataItem,
"AppointmentDate") %>
<asp:Label ID="MM" Visible="False" Text='<%#
DataBinder.Eval(Container.DataItem, "MM") %>' Runat=server />
<asp:Label ID="DD" Visible="False" Text='<%#
DataBinder.Eval(Container.DataItem, "DD") %>' Runat=server />
<asp:Label ID="YY" Visible="False" Text='<%#
DataBinder.Eval(Container.DataItem, "YY") %>' Runat=server />
</itemtemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="8AM - 10AM">
<itemtemplate>
<asp:CheckBox ID="AM1" runat="server"></asp:CheckBox>
<asp:Label ID="AM1C" Visible="False" Text='<%#
DataBinder.Eval(Container.DataItem, "AM1") %>' Runat=server />
</itemtemplate>
</asp:TemplateColumn>

+++++ C# code here +++++

private void btnSubmit_Click(object sender, System.EventArgs e)
{
string sConn = ConfigurationSettings.AppSettings["ConnectString"];
System.Web.UI.WebControls.CheckBox oCheckBox;
System.Web.UI.WebControls.Label oMM;
System.Web.UI.WebControls.Label oDD;
System.Web.UI.WebControls.Label oYY;
//System.DateTime dtTemp = System.DateTime.Now;
byte iAM1 = 0;
byte iAM2 = 0;
byte iPM1 = 0;
byte iPM2 = 0;

try
{
foreach (DataGridItem oItem in DataGrid1.Items)
{
oMM = (System.Web.UI.WebControls.Label) oItem.FindControl("MM");
oDD = (System.Web.UI.WebControls.Label) oItem.FindControl("DD");
oYY = (System.Web.UI.WebControls.Label) oItem.FindControl("YY");
System.DateTime dtTemp = new DateTime(Convert.ToInt32(oYY.Text),
Convert.ToInt32(oMM.Text), Convert.ToInt32(oDD.Text));

oCheckBox = (System.Web.UI.WebControls.CheckBox)
oItem.FindControl("AM1");

if (oCheckBox.Checked == true)
iAM1 = 1;
--
Be Cool!
Jul 21 '05 #1
0 1357

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Just D | last post by:
Hi All, Does anybody know how to write the following code? I have a database table with a few columns including: ID , "Task" , ForceRun . I need to show the DataGrid on the ASPX page with...
2
by: Sebi | last post by:
Hello all is it possible to add a checkbox in a DataGrid for Boolean Data? Thanks in advance
0
by: mike | last post by:
Hi there: I've read an excellent "how to"-article by Microsoft (no. 306227) - partly cited cited at the end of this email). I have implemented the code related to the part "How to Add a...
1
by: iforsyth | last post by:
Have a paging datagrid with a checkbox control in column(0). ViewState is enabled. I check the checkbox in first row of the grid on a page and then the program hits this event: Private Sub...
0
by: mehul | last post by:
CheckBox template always evaluate to False even if checked in a DataGrid hosted inside a TabStrip in ASP.NET Hi, I am trying to develop an ASP.NET application. I am using TabStrip (which is...
7
by: Lars Netzel | last post by:
If I put a checkbox in a datagrid (ASP.NET) and set the Autopostback to true I can catch OnChange event on checkbox but how do I then catch what DataGridItemIndex is? Can I use some Event in the...
10
by: Jennyfer J Barco | last post by:
Hello, I have a datagrid that brings some information from a query. I need to have a checkbox in each row so the user can select the rows he wants to reprint. Is it possible to have a checkbox...
2
by: Adam Knight | last post by:
Hi all, I have a datagrid with a checkbox in one column. The checkbox is set to autopostback and calls a method named UpdateMailSubscribers. The first click on the checkbox cause the page to...
9
by: Rekha | last post by:
The data is filled in datagrid. I want to know how to add a checkbox column in datagrid? In the runtime, checkbox is checked then instead of checkbox value the (caseID )column value is retained....
3
by: Fao, Sean | last post by:
I have a DataGrid that I'm adding CheckBox controls to at runtime (in the code behind) and I'm not sure if I'm doing it correctly. First of all, I noticed that the MyDataGrid.Columns.Add() method...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
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...
0
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,...

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.