Camillia
asked on
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.I tems)
{
DropDownList test = (dataItem.FindControl("ddl Status") as DropDownList);
string tt = test.SelectedValue; //**** always "WH" !!!
}
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.I
{
DropDownList test = (dataItem.FindControl("ddl
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>
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>
ASKER
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?
>> 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?
ASKER
No, this line is not correct. There's no "SelectedValue" for ddl's main tag:
<asp:DropDownList ID="ddlStatus" runat="server"
SelectedValue='<%# Bind("Status") %>' >
<asp:DropDownList ID="ddlStatus" runat="server"
SelectedValue='<%# Bind("Status") %>' >
ASKER
I tried this as well:
string tt = test.SelectedItem.Value.To String();
But still defaults to first ddl item
string tt = test.SelectedItem.Value.To
But still defaults to first ddl item
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Although it does not show up in the autofill options, SelectedValue is the correct attribute to which you bind.
What you are actually trying to achieve?