Retrieving SelectedValue from DropDownList

A

AlBruAn

I have a few DropDownList controls used for new record entry in the footer of
a datagrid and I want to limit the options available in one list based on
what is selected in a previous list; I've seen examples of this where the
DropDownLists are used in edit mode, but none for data entry mode. The
footer cell for one column is defined as:

<FooterTemplate>
<asp:DropDownList ID="cboWorkflowID" AutoPostBack="true"
OnSelectedIndexChanged="OnSelectedIndexChanged" DataSource='<%#
GetWorkflowIDs() %>' Runat="server" DataMember="WorkflowID"
DataTextField="WorkflowID" />
</FooterTemplate>

Setting a breakpoint in the function OnSelectedIndexChanged, I am able to
pull up the Command Window and see the SelectedValue by typing in:
? ( ListControl ) sender. Despite that, I can't for the life of me figure
out how to programmatically retrieve the value. I've tried virtually every
permutation of ((DropDownList)(_grid.Items[0].FindControl("cboWorkflowID")))
I can think of, but to no avail. Is there a way?

Regards,

Allen Anderson
 
B

Brock Allen

((DropDownList)(_grid.Items[0].FindControl("cboWorkflowID"))) I can
think of, but to no avail. Is there a way?

You're close, but grab the _grid.Item[x].FindControl where x is the row in
the grid for the footer.
 
A

AlBruAn

Brock Allen said:
((DropDownList)(_grid.Items[0].FindControl("cboWorkflowID"))) I can
think of, but to no avail. Is there a way?

You're close, but grab the _grid.Item[x].FindControl where x is the row in
the grid for the footer.
Brock,

I tried (((DropDownList)(_grid.Items[9].FindControl("cboWorkflowID"))) but
it refuses to work since a count of 9 is returned when asking for
_grid.Items.Count.

Allen
 
B

Brock Allen

Collections are zero-based, so access the position at Count - 1




Brock Allen said:
((DropDownList)(_grid.Items[0].FindControl("cboWorkflowID"))) I can
think of, but to no avail. Is there a way?
You're close, but grab the _grid.Item[x].FindControl where x is the
row in the grid for the footer.
Brock,

I tried (((DropDownList)(_grid.Items[9].FindControl("cboWorkflowID")))
but it refuses to work since a count of 9 is returned when asking for
_grid.Items.Count.

Allen
 
A

AlBruAn

I'm aware collections are zero-based, that's why I said using 9 as in
Items[9] wouldn't work. The footer row is currently the 9th row in the grid,
so your suggestion of using
((DropDownList))(_grid.Items[9].FindControl("cboWorkflowID"))) doesn't work.
Any other idea?

Thanks!

Allen

Brock Allen said:
Collections are zero-based, so access the position at Count - 1




Brock Allen said:
((DropDownList)(_grid.Items[0].FindControl("cboWorkflowID"))) I can
think of, but to no avail. Is there a way?

You're close, but grab the _grid.Item[x].FindControl where x is the
row in the grid for the footer.
Brock,

I tried (((DropDownList)(_grid.Items[9].FindControl("cboWorkflowID")))
but it refuses to work since a count of 9 is returned when asking for
_grid.Items.Count.

Allen
 
A

AlBruAn

I'm starting to confuse myself now...LOL. There are currently nine (0
through 8) rows of data, so that would make the footer row the tenth row.
Regardless, _grid.Items.Count returns a value of 9 with the last index being
8, which is to be expected; consequently,
((DropDownList)(_grid.Items[9].FindControl("cboWorkflowID"))) can never
successfully execute, much less return the SelectedValue for that
DropDownList control. So I'm still stuck without a way of finding what value
was selected in the control.

AlBruAn said:
I'm aware collections are zero-based, that's why I said using 9 as in
Items[9] wouldn't work. The footer row is currently the 9th row in the grid,
so your suggestion of using
((DropDownList))(_grid.Items[9].FindControl("cboWorkflowID"))) doesn't work.
Any other idea?

Thanks!

Allen

Brock Allen said:
Collections are zero-based, so access the position at Count - 1




:

((DropDownList)(_grid.Items[0].FindControl("cboWorkflowID"))) I can
think of, but to no avail. Is there a way?

You're close, but grab the _grid.Item[x].FindControl where x is the
row in the grid for the footer.


Brock,

I tried (((DropDownList)(_grid.Items[9].FindControl("cboWorkflowID")))
but it refuses to work since a count of 9 is returned when asking for
_grid.Items.Count.

Allen
 
B

Brock Allen

You know what, I think we're mixing topics here. Do you have a DataGrid or
a DataList? A DataGrid doesn't have a FooterTemplate. If it's a DataList
then you just directly use the controls you've declared in there.




I'm starting to confuse myself now...LOL. There are currently nine (0
through 8) rows of data, so that would make the footer row the tenth
row. Regardless, _grid.Items.Count returns a value of 9 with the last
index being 8, which is to be expected; consequently,
((DropDownList)(_grid.Items[9].FindControl("cboWorkflowID"))) can
never successfully execute, much less return the SelectedValue for
that DropDownList control. So I'm still stuck without a way of
finding what value was selected in the control.

AlBruAn said:
I'm aware collections are zero-based, that's why I said using 9 as in
Items[9] wouldn't work. The footer row is currently the 9th row in
the grid, so your suggestion of using
((DropDownList))(_grid.Items[9].FindControl("cboWorkflowID")))
doesn't work. Any other idea?

Thanks!

Allen

Brock Allen said:
Collections are zero-based, so access the position at Count - 1


:

((DropDownList)(_grid.Items[0].FindControl("cboWorkflowID"))) I
can think of, but to no avail. Is there a way?

You're close, but grab the _grid.Item[x].FindControl where x is
the row in the grid for the footer.


Brock,

I tried
(((DropDownList)(_grid.Items[9].FindControl("cboWorkflowID"))) but
it refuses to work since a count of 9 is returned when asking for
_grid.Items.Count.

Allen
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,743
Messages
2,569,478
Members
44,898
Latest member
BlairH7607

Latest Threads

Top