473,756 Members | 8,174 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Need help retrieving controls dynamically added to GridView

I need some advice on handling dynamically added controls in a
GridView.

My app takes an uploaded CSV file containing addresses, converts it to
a DataTable, databinds the DataTable to a GridView, accepts information
via dropdowns embedded in the first row of the GridView about which
incoming fields should go to which database fields, and writes the data
to the database.

The incoming data has an arbitrary number of columns so I create the
GridView dynamically. When I create the DataTable I add an extra row at
the beginning so that the first line of the GridView will contain no
data. I then add the dropdown controls dynamically to each of the cells
in this row, giving each dropdown a unique ID, ie

dt.Rows.InsertA t(r, 0)
GridView1.DataS ource = dt
GridView1.DataB ind()

Dim gvr As GridViewRow
gvr = GridView1.Rows( 0)
Dim j As Integer
For j = 0 To gvr.Cells.Count - 1
Dim dd As New DropDownList
dd.ID = "DropDownLi st" & j.ToString.Trim
dd.Items.Add("- nothing selected -")
dd.Items.Add("A ddr Line 1")
dd.Items.Add("T own")
dd.Items.Add("C ountry")
dd.Items.Add("e tc")
gvr.Cells(j).Co ntrols.Add(dd)
Next

That all seems to work fine. The GridView appears and the first row
contains dropdowns.

But when I do the postback and loop through GridViewRow(0) to retrieve
each DropDownX.Selec tedValue, either in Page_Load or GridView1_Load,
the dropdowns have disappeared. The first row is blank. The following
rows show the actual data as normal.

I understand I have to recreate the dropdowns on each postback as
they're dynamically created, but I can't even get that far.

Maybe I don't know quite enough about the control lifecycle to
understand what's going on. What do I need to do to be able to
retrieve the dropdowns?

Thanks,

Chris N

Jul 18 '06 #1
0 1885

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

Similar topics

5
3734
by: Dennis Fazekas | last post by:
Greetings, I am creating a web form which will all the user to add an unlimited number of email addresses. Basically I have 3 buttons, "Add Another Email", "-" to remove, and a "Save" button. When the user clicks the "Add another email" it will call a client side JavaScript function, add_email, which will dynamically add a new set of controls to the webpage using the innerHTML method. It appears to work perfectly fine in the browser. The...
3
2542
by: Dotnet Gruven | last post by:
I've built a WebForm with a Table added dynamically in Page_Load when IsPostBack is false. The table includes a couple of TextBoxes, RadioButtonLists and CheckboxLists. On postback, those controls are not present nor their valves in Request.Form.AllKeys.
3
2884
by: keithb | last post by:
My code dynamically adds template fields to a GridView control. Everything seems to work OK, except when updating, because I haven't found a way to reference the dynamically added textboxes. FindControl doesn't work, and the textboxes cannot be accessed using grid.Rows.Cells.Control. Can someone help? Thanks, Keith
2
5232
by: mangomadman | last post by:
Has anyone solved the problem with adding Controls dynamically to a GridView at runtime? I encounter the problem that GridView doesn't save these Controls on post back, which makes them useless.
1
1749
by: keithb | last post by:
I have found that I must re-create dynamically added controls on every postback in order to find and access them programatically. The controls I am working with are inside a GridView control. When the edit button is clicked, a postback occurs and the control are re-created. This causes an additional set of columns to be created in the GridView control, so that all of the dynamically added controls exist in 2 places on the screen. How can I...
4
5139
by: scottcly | last post by:
I have a simple editor with a Gridview and a DetailsView. The Gridview handles DELETE and the DetailsView handles UPDATE and ADD. A panel around each one and some minor event handling is used to control which one is visible based on buttons pushed. I can do single operations, but I get an error when I click SELECT on the GRIDVIEW, then UPDATE on the DetailsView then SELECT on the Gridview again. I will have to send the code in a follow-on...
4
2541
by: Mark Olbert | last post by:
I'm running into a well-described issue in the ASPNET model that I haven't found a good work around for. I have a GridView to which I dynamically add data-bound TemplateFields at run-time. The specific fields that are added depend on the state of the application. The contents of these fields displays properly after they are first initialized, but not after postback (e.g., just a simple button control that doesn't do anything except...
5
4454
by: Nathan Sokalski | last post by:
I have a custom control that I wrote (I inherit from System.Web.UI.WebControls.CompositeControl). I dynamically add this control to my Page, but I was told that dynamically added controls do not survive postback. This seems to be true. However, this seems to make dynamically adding controls rather pointless to me, since if you cannot retrieve the values of the controls when you perform a postback, why add the controls in the firstplace?...
1
1118
by: vingomail | last post by:
I want a sample code for how to retrieve the values of dynamically generated text box controls at runtime. One thing I ve more number of textbox controls and also generated ids for that controls. i added this controls into a placeholder. but i dont know to retrieve those values in the action of button... can someone help me... Thanks
0
9212
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 synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9790
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9779
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
9645
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
8645
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...
0
6473
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();...
1
3742
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
3276
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2612
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.