473,804 Members | 2,536 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Retrieving dynamically added items on postback

I have a dropdown list in a datagrid which I am dynamically adding
items to with JavaScript.

When I try to access the value of the dropdown list on postback, there
is no value. The value is null. I get the feeling I'm supposed to do
something else, but I'm not sure what.

If anyone can help, I would appriciate it. Thanks.

foreach( DataGridItem di in DataGrid1.Items )
{

DropDownList ddl = (DropDownList) di.FindControl( "ddlItems") ;
Label lblID = (Label)di.FindC ontrol("id");

int id = Convert.ToInt32 (lblID.Text);
int itemvalue = Convert.ToInt32 (ddl.SelectedVa lue); // the
item value here is null

// Do stuff with items here.
}

May 30 '06 #1
2 1632
the browser only posts back the selected value of a drop down, so the server
has no way of knowing the changes the client code made. the postback data
support in the dropdown, expects the postback value to be in its list of
value, if not, it ignores it.

you shoudl decide hoiw the client code is going to pass the additional value
to the browser. if you only need the selected value, then no more client
code is required. then in the server code, in OnInit (before postback data
is processed), you need to add the selects postback value (look in the forms
collection) as a valid value in the dropdown.

-- bruce (sqlwork.com)
<ec****@gmail.c om> wrote in message
news:11******** **************@ j55g2000cwa.goo glegroups.com.. .
I have a dropdown list in a datagrid which I am dynamically adding
items to with JavaScript.

When I try to access the value of the dropdown list on postback, there
is no value. The value is null. I get the feeling I'm supposed to do
something else, but I'm not sure what.

If anyone can help, I would appriciate it. Thanks.

foreach( DataGridItem di in DataGrid1.Items )
{

DropDownList ddl = (DropDownList) di.FindControl( "ddlItems") ;
Label lblID = (Label)di.FindC ontrol("id");

int id = Convert.ToInt32 (lblID.Text);
int itemvalue = Convert.ToInt32 (ddl.SelectedVa lue); // the
item value here is null

// Do stuff with items here.
}

May 30 '06 #2
You might try the Request.Form[controlName] property to get the selected
value from the drop down list, though you will need to use the control name
passed to the client. Since you are embedding the drop down list in a
datagrid, it is going to be some combination of the grid id and the drop down
list id. I cannot remember off the top of my head, but you can view the HTML
source to see the pattern.
May 30 '06 #3

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

Similar topics

1
1926
by: Joel Reinford | last post by:
I am working on an ASP.NET web app. One of the pages will be using several user controls. The controls will be loaded dynamically based on SQL Server data. I need to be able to retrieve the values from the individual fields in those user controls. So far I am not able to access the controls at postback. Any suggestions would be appreciated. Joel Reinford
4
5485
by: DotNetJunky | last post by:
I have built a control that runs an on-line help system. Depending on the category you selected via dropdownlist, it goes out and gets the child subcategories, and if there are any, adds a new dropdownlist to the screen for selection. This continues until there are no children, and then it checks for a help article list based on that last selection and displays actual articles for display. Adding the controls and getting everything...
4
1603
by: Sandeep | last post by:
Hi I am doing one thing in my website ,actually i want to add controls dynamically to a web form and want to access the elements but when i postback the form,and access that control, it gives error Object reference not set to an instance of an object. ************************************************************************ ************************************************************************** Public Class index2 Inherits...
4
3123
by: Harry | last post by:
Hello, I have a page with a RadioButtonList and a PlaceHolder control. The RadioButtonList's AutoPostBack attribute is set to TRUE and its SelectedIndexChanged event loads one of three UserControls into the PlaceHolder's child control collection depending upon which of the three radio buttons is selected. Each of the three UserControls have postback events themselves triggered by button clicks. The problem I'm having is keeping track of...
3
2545
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.
1
1803
by: Mike | last post by:
Hi, I am having troubles dealing with dynamically created WebControls. I have this HTML code: <form id="Form1" runat="server" method="post"> <table width="960" align="center"> <tr> <td align="center"> ......
0
1890
by: yeltsin27 | last post by:
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...
5
4720
by: =?Utf-8?B?TWFyYyBXb29sZnNvbg==?= | last post by:
Hi, I have a strange issue occurring with LinkButtons that are dynamically added to each (data) row of my DataGrid on that grid's ItemDataBound event. Each LinkButton is assigned its own event handler to deal with the Command event, but for some reason I can get this to work in a C# project but not in a newly created VB.NET one. The relevant VB.NET is as follows:
5
4455
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?...
0
9591
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
10594
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10343
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
7631
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
6861
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
5529
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
5667
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4306
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
3831
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.