• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 921
  • 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
Cloud Class® Course: Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

 
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

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