473,554 Members | 2,479 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 1621
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
1901
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...
4
5465
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...
4
1591
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. ************************************************************************...
4
3099
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...
3
2527
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
1781
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
1878
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...
5
4702
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...
5
4445
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...
0
7615
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
7539
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
7581
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
7897
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...
1
5446
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
3589
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...
1
2030
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
1149
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
858
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.