473,413 Members | 1,993 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,413 software developers and data experts.

WEB APP Datalist Checkbox in C#

I create a datalist from a datatable that is created in code on the page. I have all of my values assigned to dropdowns and labels inside the DL and it runs through them.

Everything works great

BUT

I have added a checkbox to Datalist and now want to set visable= false to the items in the datalist of the checkbox is check (on post back of course).. But I cannot find where I should put my code for this. in what function? selectedindex, itemcreated etc... None will work.. I think I am putting it in the wrong place so when it posts back it make the changes to the datalist

Expand|Select|Wrap|Line Numbers
  1. protected void dlSpanDays_ItemCommand(object source, DataListCommandEventArgs e)
  2.     {
  3.         CheckBox worked = (CheckBox)e.Item.FindControl("chkWork");
  4.  
  5.         Label lblDayer = (Label)e.Item.FindControl("lblDateDayName");
  6.  
  7.         if (worked.Checked == false)
  8.         {
  9.             lblDayer.Visible = false;
  10.         }
  11.  
  12.     }
Any help would be greatly appreciated!!

Thanks
Ryan
Nov 29 '07 #1
1 1437
I found the easiest answer I think. If you come up with a better one please let me know.

On a datalist it is a bit different than a GridView. Even on ItemCeated with checkboxes.

if you set a condition like in the first post above the checkbox will always be the default setting of the checkbox, it does not get a new setting when you check it and postback and reload. It is static and always remains the same from my experience. There where tones of info using a dataset and storing the true/false info and rebinding the datatable. Instead of doing that I found that if you do the following on the CheckedChanged property of the checkbox, you can modify any control within the same row of the datalist. I just wanted to enable disable controls insidea datalist row, noting major but this could be expanded to do other things I am sure.

Expand|Select|Wrap|Line Numbers
  1. protected void chkWork_CheckedChanged(object sender, EventArgs e)
  2.     {
  3.  
  4.         CheckBox worked = (CheckBox)sender;
  5.         Label lblWorkOn1 = (Label)worked.NamingContainer.FindControl("lblWorkOn");
  6.         DropDownList ddlspanhourstart1 = (DropDownList)
  7.  
  8.         if (worked.Checked == true)
  9.         {
  10.             ddlspanhourstart1.Enabled = true;
  11.         }
  12.         else
  13.         {
  14.             ddlspanhourstart1.Enabled = false;
  15.         }
  16.  
  17.     }
When doing it this way it seems to me that you save server and client resources depending on what you want to do. It is at least better than loading all of the datasets into vewstate or session and running through all of them again.

I got the base info here and modified it for datalist instead of Gridview The gridview info is here

http://geekswithblogs.net/azamsharp/.../10/65433.aspx

Just my 2 cents..

Ryan
Nov 30 '07 #2

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

Similar topics

1
by: wsyeager36 | last post by:
I have a datagrid inside a datalist. The datalist shows parent info and the datagrid shows the child info for that parent. There is a checkbox on each row of the child datagrid. Also inside the...
1
by: bill yeager | last post by:
I have a datagrid control within a datalist control. When I try and do a "Find" on the control, the object comes back with nothing and then my pgm crashes. I am 100% sure that my datagird inside...
4
by: mahsa | last post by:
my problem dosent solve yet I want to have claa void in onclick of my check bov if I us function setProps ( ) msg.innerText = "llll"; in <datalist> <ItemTemplate><input type="checkbox"...
1
by: Glenn Owens | last post by:
Here's the scenario: I have a DataList populated from a datatable sitting inside a fieldset. Each element (row) in the Datalist has the following child controls: asp:checkbox, asp:image,...
2
by: Vadivel Kumar | last post by:
I have one datalist which contains one item template. In that, iam printing a value taken from the sql table and one check box. Now, the user will select some checkbox and press a button and that...
1
by: VB Programmer | last post by:
Simple: I have a datalist that is holding a bunch of job opportunities. Beside each opp (in the item template) there's a checkbox that says "apply". After the datalist there's a button that...
1
by: SP | last post by:
Hello there, I have a DataList create as below. <asp:DataList ID="dl_Immunpsuppressive_Main" Runat="server" Width="100%"> <ItemTemplate> <table id="Immunpsuppressive_Main" width="100%"...
1
by: rn5a | last post by:
A ASPX page has a DataList control with a few Labels. This page also has a CheckBox which resides OUTSIDE the DataList. By default, this CheckBox is checked. If the CheckBox is checked, then the...
0
by: AleXmanFree | last post by:
Hi, I have this kind of problem, In my asp.net page i use DataList and user control that is repeated in DataList. This user control has in it a checkbox , so everytime user clicks on checkbox...
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...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
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,...
0
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...

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.