468,783 Members | 1,593 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,783 developers. It's quick & easy.

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.FindControl("id");

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

// Do stuff with items here.
}

May 30 '06 #1
2 1446
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.com> wrote in message
news:11**********************@j55g2000cwa.googlegr oups.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.FindControl("id");

int id = Convert.ToInt32(lblID.Text);
int itemvalue = Convert.ToInt32(ddl.SelectedValue); // 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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by Sandeep | last post: by
4 posts views Thread by Harry | last post: by
1 post views Thread by Mike | last post: by
5 posts views Thread by =?Utf-8?B?TWFyYyBXb29sZnNvbg==?= | last post: by
5 posts views Thread by Nathan Sokalski | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
2 posts views Thread by Marin | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.