473,397 Members | 2,056 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,397 software developers and data experts.

Tell me this isn't a bug. (databinding inside a usercontrol...)

I created a user control that, had a datalist with checkboxes inside of the
item template. These checkboxes would not retain state. For instance, if I
set them to checked inside of the load event of the UserControl, they would
appear false(the default value) when inside the top level datagrid.

Here's the walkthrough (tried to make it as quick as possible):

Start a new ASP.NET Web Application project.

1. Create a usercontrol. (UserControl1)
2. Add a datalist to it. (DataList1)
3. To the item template, add a checkbox (Checkbox1)
4. Add this code to the Page_Load event of ** UserControl1 **
----------------------------------------------------------------------------
'Put user code to initialize the page here
datalist1.DataSource = New String() {"Item1", "Item2", "Item3"}
datalist1.DataBind()
For Each I As DataListItem In datalist1.Items
Dim chk As CheckBox = I.FindControl("CheckBox1")
chk.Checked = True
Next
-----------------------------------------------------------------------------
(The text "CheckBox1" should be the name of the checkbox you added in step
3, if you left it at the default, then you dont have to change anything)

5. The first part is done. Go to the default web form that was created (most
likely WebForm1.aspx)
6. Drop a datagrid onto that form(Datagrid1), and open the property builder.
7. Uncheck "automatically generate columns" & add the following 2 columns:
-The standard edit/update/cancel button column
-one template column.
8. Close property pages and go to the Edit Template for the Template column:
- Drop an instance of the usercontrol (UserControl1) you created in step 1.
9. Close the template editor, and paste the following code for the
datagrid1_EditCommand event:

-----------------------------------------------------------------------------------------
Datagrid1.DataSource = New String() {"Main Item 1", "Main Item 2", "Main
Item 3"}
Datagrid1.EditItemIndex = e.Item.ItemIndex
Datagrid1.DataBind(
------------------------------------------------------------------------------------------

10. Finally, paste the following code in the Page_Load event of WebForm1

-------------------------------------------------------------------------------
Datagrid1.DataSource = New String() {"Main Item 1", "Main Item 2", "Main
Item 3"}
Datagrid1.DataBind(
-------------------------------------------------------------------------------

Execute the project:

Observe the checkboxes are checked in each instance of the usercontrol
inside the rows of the datagrid.
Now click one of the edit buttons.
Notices all the checkboxes are now false.

I struggled for a few days with this, any replies greatly appreciated.
Nov 18 '05 #1
0 1096

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

Similar topics

3
by: DraguVaso | last post by:
Hi, I'm having the following situation: - A class clsFournisseur with public property's which raise a MyPropertyChanged-event in the Set-method for each Property. Public Event NomChanged As...
1
by: | last post by:
Hi, I posted a message a while ago about programatically databinding and got a response that did not make sense to me. Here's a brief description of what I want to do. If I create a regular...
0
by: Rajesh Tiwari | last post by:
hi group can we use a usercontrol inside a usercontrol. i mean can we use <%Register tagprefix..... src=....ascx%> in an ascx file. thanks in advance -- Rajesh Tiwari
2
by: Jason Wright via .NET 247 | last post by:
Hiya, I've created a UserControl with some Custom properties and assigned databinding expressions to the properties in the aspx. Does anyone know why these expressions are not being evaluated? ...
0
by: nail | last post by:
Hi. Think the following scenario. UC1 with a textbox control and a button control. UC2 with a textbox control and a button control too. I need to, on the click event of the button inside the...
6
by: John Bailey | last post by:
I have a web page with a formview, and a multiview in the formview. When I databind the values inside the multiview views, there is no option for two-way databinding. The form populates fine, but...
13
by: Michael Maes | last post by:
Hi, I have a UserControl containing some controls of which one is a ComboBox. All the InternalControls are Private and some are allowed to be accessed through Public Methods. One of the things I...
8
by: Daniel | last post by:
Hi, Does anyone know if it is possible to put an aspx page inside of another? OR run an aspx page and capture the output as a string and then write this out to a page.... So for example say...
3
by: Mauro D. | last post by:
Hi, In my usercontrol I bind the BindingSource I pass via property to all the control inside the usercontrol. For example Control ctl=new TextBox(); ctl.DataBindings.Add("Text", binding,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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
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
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.