473,545 Members | 2,095 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

.NET3.0/C# How to set Selected property...

2 New Member
Problem: How to set the Selected property of items in a CheckBoxList in the EditItemTemplat e of a FormView control that has been populated initially using an ObjectDataSourc e.

I have a column in a SQL Server 2005 table for a person's race. A CheckBoxList is used to get this information from the user. Since a person can be multi-racial, they can check multiple checkboxes. The checked values are saved as a comma-delimited string to the database.

I have another GUI used by someone who can edit a person's information. An ObjectDataSourc e is used to populate a FormView control. The itemtemplate shows the comma-delimited string, e.g., 'African American, White'. In edit mode I want to show a CheckBoxList with all the possible values and set the Selected property of items matching what has come down from the database.

What is the best way to do this? I can't seem to get a reference to the CheckBoxList using the FormView's FindControl method and I'm not sure which event to use--I tried ItemCreated, DataBound, and PageLoad.

Once I know which event to use, I was going to do something like the following:

Expand|Select|Wrap|Line Numbers
  1.  
  2. Child c = (Child)HttpContext.Current.Session["ChildInfo"];
  3. if (c != null)
  4. {
  5.    string[] tempArray = c.Race.Split(',');
  6.    CheckBoxList cbl = viewDemog.FindControl("cblRace");
  7.    for (int i = 0; i < cbl.Items.Count; i++)
  8.       for (int j = 0; j < tempArray.Length; j++)
  9.          if (cbl.Items[i].Text == tempArray[j])
  10.             cbl.Items[i].Selected = true;
  11. }
  12.  
Thanks in advance
GM
Nov 25 '07 #1
1 1819
Usha Reddy
2 New Member
Hi!!

Below is the code to set the Selected Property of Items in CheckBox in the EditItemTemplat e of the Grid (in VB.Net)

CType(gvMaster. Rows(intEditRow ).FindControl(" Edit_Item"), CheckBox).Check ed = True


You can use PreRender Event of the GridView to write this code

Note: This event will Trigger everytime So be clear and use some logic to not Trigger this code everytime or else you will get the error like "object Referrence not set to an instance of an object"
Nov 26 '07 #2

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

Similar topics

8
2822
by: Vipin Kedia | last post by:
Hi I have written a code for showing the list boxes as selected using a Listitem and the selected property of the items. Now I have 2 list boxes in my page. But it shows only the selected values of the last list box in both the list boxes. If i reverse the calls to the filllistbox methods it shows the value selected for the 1st list box in...
8
12069
by: Zlatko Matiæ | last post by:
There is a form (single form) and a combobox. I want that current record of the form is adjusted according to selected value in the combobox. Cuurrent record should be the same as the value in the combobox. What is the solution? Thank you in advance.
5
10805
by: Kris Rockwell | last post by:
Hello (again), I have gotten the dropdown list functionality to work through a few tricks (probably not the most efficient, but it works) but I am not sure how to set the default selected value. I have tried setting various values to represent the default value with little success. Essentially I am looking to have the first item in the list...
4
2434
by: Moe Sizlak | last post by:
Hi There, I am trying to return the value of a listbox control that is included as a user control, I can return the name of the control but I can't access the integer value of the selected item, what do I need to do in order to return the "option value" of the control? Moe !--- returned value of the control
10
10720
by: dhnriverside | last post by:
Hi guys Still having a problem with this dropdownlist. Basically, I've got 4. The first 2 work fine, then my code crashes on the 3rd. ddlEndTimeHour.Items.FindByValue(endTime).Selected = true; Where endTime is a string containing "15".
1
7411
by: g | last post by:
I have a user control that contains a dropdownlist. Using a public property, I can get the selected item. However, I am unsure of how to use that same public property to set the selected item. Here's my code: private string m_item = ""; public string Item { get {
1
415
by: (js) | last post by:
sorry for ma bad english sorry for maybe a little boring question but I want to ask if it is possible writing a .net3.0 programs in vs2005. The company I am working in want to migrate project from vs2003 and .net1.0 to vs2005 and .net2.0 framework but all things are not clear for me and I have question - it is not better to migrate to...
0
935
by: snehal12345 | last post by:
I have created 1 contextmenu for a listbox in C#.net 3.0 . For that context menu I have written one event handler for mouseup event . But when i click on contextmenu item that event is not captured. I have done following: { /*in constructor of main window */ listbox1.ContextMenu.Items.Add("save"); listbox1.ContextMenu.MouseUp += new...
0
1316
by: bhappy | last post by:
Hi All, I am doing a project in ASP.Net3.5, I needs to write test methods for my code. Please any one help me on how to use Test Driven Development(TDD) in my project? What are the softwares needed? I had .Net3.5 with service pack1 installed in my pc. Thanks.
0
7464
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7396
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...
1
7413
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
5968
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...
1
5323
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...
0
3440
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1874
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
1
1012
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
700
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...

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.