Dropdownlist value always is the first value

We're using RadControls (Telerik). Similar to AJAX.
I have 4 items in the ddl. Whatever i choose and then click a button, the value is always the first item in the ddl... not sure what i'm missing,,this is what i have:

In ItemDataBound, I loop thru the items but it's always the first ddl value:

 foreach (GridDataItem dataItem in grdItems.MasterTableView.Items)  
            {

                DropDownList test = (dataItem.FindControl("ddlStatus") as DropDownList);
                string tt = test.SelectedValue; //**** always "WH" !!!

            }
<rad:GridTemplateColumn HeaderText="New Status">
                                                                 <ItemTemplate><asp:DropDownList ID="ddlStatus" runat="server">
                                                                                 <asp:ListItem Value="WH"  Text="Sent"></asp:ListItem>
                                                                                 <asp:ListItem Value="NA" Text="NA"></asp:ListItem>
                                                                                 <asp:ListItem Value="Canceled" Text="Canceled"></asp:ListItem>
                                                                                 <asp:ListItem Value="Hold" Text="Hold"></asp:ListItem>
                                                                               </asp:DropDownList>
                                                                 </ItemTemplate>
                                                                </rad:GridTemplateColumn>

Open in new window

LVL 8
CamilliaAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

rpkhareCommented:
This is because you are retrieving the SelectedValue. By default the first item is selected. You are just asking to show the selected item.

What you are actually trying to achieve?
0
GreymanMSCCommented:
I suspect  you may wish to bind the control to the container's dataobject.
<ItemTemplate><asp:DropDownList ID="ddlStatus" runat="server"
        SelectedValue='<%# Bind("Status") %>'
    >
        <asp:ListItem Value="WH"  Text="Sent"></asp:ListItem>
        <asp:ListItem Value="NA" Text="NA"></asp:ListItem>
        <asp:ListItem Value="Canceled" Text="Canceled"></asp:ListItem>
        <asp:ListItem Value="Hold" Text="Hold"></asp:ListItem>
    </asp:DropDownList>
</ItemTemplate>

Open in new window

0
CamilliaAuthor Commented:
I will try GreymanMSC's method when i get to work...

>> This is because you are retrieving the SelectedValue
If I have 4 items in the ddl, and user selects item2, I want that item2. Whatever the user selected from ddl... I think that's correct: selectedValue ...no?

0
Exploring SharePoint 2016

Explore SharePoint 2016, the web-based, collaborative platform that integrates with Microsoft Office to provide intranets, secure document management, and collaboration so you can develop your online and offline capabilities.

CamilliaAuthor Commented:
No, this line is not correct. There's no "SelectedValue" for ddl's main tag:

<asp:DropDownList ID="ddlStatus" runat="server"
        SelectedValue='<%# Bind("Status") %>'   >
0
CamilliaAuthor Commented:
I tried this as well:

string tt = test.SelectedItem.Value.ToString();

But still defaults to first ddl item
0
CamilliaAuthor Commented:
if I add AutoPostback and onSelectedIndexChanged..then I can grab the changed value...but do I actually need this??


<asp:DropDownList ID="ddlNextStatus"  AutoPostBack="true" OnSelectedIndexChanged="ddlTest"  runat="server">

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
GreymanMSCCommented:
Although it does not show up in the autofill options, SelectedValue is the correct attribute to which you bind.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.