473,670 Members | 2,563 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.DataS ource = New String() {"Item1", "Item2", "Item3"}
datalist1.DataB ind()
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 "automatica lly 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_EditC ommand event:

-----------------------------------------------------------------------------------------
Datagrid1.DataS ource = New String() {"Main Item 1", "Main Item 2", "Main
Item 3"}
Datagrid1.EditI temIndex = e.Item.ItemInde x
Datagrid1.DataB ind(
------------------------------------------------------------------------------------------

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

-------------------------------------------------------------------------------
Datagrid1.DataS ource = New String() {"Main Item 1", "Main Item 2", "Main
Item 3"}
Datagrid1.DataB ind(
-------------------------------------------------------------------------------

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 1112

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

Similar topics

3
1501
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 EventHandler Public Property Nom() As String Get Return m_strNom
1
1407
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 aspx page I can use the designer to create a DataAdapter and generate a typed dataset. I can then put a datalist on my page, set its datasourse property to my dataset and put a Textbox inside the
0
960
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
1658
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? eg. <uc1:ControlX id="la" runat="server" ClientClick='javascriptfunction(<%# DataBinder.Eval(Container.DataItem, "Id")%>)' /> after processing renders in html as <table id="la" onclick="javascriptfunction(<%#...
0
1133
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 UC1, give a value to the textbox inside the UC2. In the real scenario I will have a lot of UC2, one accessing another.
6
3563
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 when it calls the update method, it calls it with no parameters. Is there just no support for two-way databinding inside these controls, or is there a technique I am missing?
13
5333
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 would like to do (of course) is set the DataBindings. Something clearly is wrong with the approach I use, because I can't set the Properties in the Designer, the DataSource-Property appears like 'ReadOnly', there is no "dropdown" with the list from...
8
1904
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 you have a page that takes an id number as a query string and displays different things based on that id number. If you were able to loop through running the aspx pages with id=100, id=200,
3
2816
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, prop, false, DataSourceUpdateMode.OnPropertyChanged);
1
8591
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 most users, this new feature is actually very convenient. If you want to control the update process,...
0
8659
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7412
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 launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6212
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 instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5683
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4208
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4388
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2799
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
2
1791
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.