• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 909
  • Last Modified:

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

0
Camillia
Asked:
Camillia
  • 4
  • 2
1 Solution
 
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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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
 
GreymanMSCCommented:
Although it does not show up in the autofill options, SelectedValue is the correct attribute to which you bind.
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now