This is a migrated thread and some comments may be shown as answers.

ComboBox SelectedValue Null or ""

4 Answers 329 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
ADAPT
Top achievements
Rank 2
ADAPT asked on 19 Feb 2014, 11:13 AM
Hello
I am trying to grab the SelectedValue of a RadComboBox unsuccessfully on button click.

protected void smsBtn_Click(System.Object sender, System.EventArgs e)
{
        MyClass MC= new MyClass (_FID, emTxBx.Text);
{
if (!MC.IsError)
{

string _carrier = carrierRcb.SelectedValue;

MC.SMSMessage(_FID, _carrier, cellTxBx.Text);

statusLbl.ForeColor = System.Drawing.Color.Red;
statusLbl.Text = "Your Code Key has been sent.";
statusPnl.Visible = true;
}
else
{
statusLbl.ForeColor = System.Drawing.Color.Red;
statusLbl.Text = "There was an error sending your request.";
statusPnl.Visible = true;
}
}

}


Seems like a simple thing to do. Am I missing something here?

4 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 19 Feb 2014, 11:41 AM
Hi,

Please have a look into the sample code snippet which works fine at my end.

ASPX:
<telerik:RadComboBox ID="RadComboBox1" runat="server">
    <Items>
        <telerik:RadComboBoxItem Text="Item1" Value="0" />
        <telerik:RadComboBoxItem Text="Item2" Value="1" />
        <telerik:RadComboBoxItem Text="Item3" Value="2" />
    </Items>
</telerik:RadComboBox>
<telerik:RadButton ID="RadButton1" runat="server" Text="Get SelectedItem" OnClick="RadButton1_Click">
</telerik:RadButton>

C#:
protected void RadButton1_Click(object sender, EventArgs e)
{
    string text = RadComboBox1.SelectedItem.Text;
    string value = RadComboBox1.SelectedValue;
}

Thanks,
Shinu.
0
ADAPT
Top achievements
Rank 2
answered on 19 Feb 2014, 11:52 AM
Hi and thanks for your response however your solution does not work for me. Here is my binding method and page view code:

​ StandardClass RC = new StandardClass();
if (!RC.IsError)
{
carrierRcb.DataSource = RC.ReturnCarriers();
carrierRcb.DataTextField = "Carrier";
carrierRcb.DataValueField = "str";
carrierRcb.DataBind();
}


<asp:TableRow>
<asp:TableCell CssClass="cellPad">
<asp:Label ID="carrierLbl" runat="server" CssClass="label" />
</asp:TableCell>
<asp:TableCell CssClass="cellPad">
<telerik:RadComboBox ID="carrierRcb" runat="server" EmptyMessage="Select your Cell Phone Carrier..." Skin="Windows7" />
</asp:TableCell>
</asp:TableRow>

I do not define the combobox via items list and niether string works in my case.
0
Patrice
Top achievements
Rank 1
answered on 20 Feb 2014, 07:26 PM
I've got the same issue.
Works with RadcomboboxItem from aspx.
but with a set of datasource from the codebehind doesn't work, use OnSelectedIndexChanged to check the new index,
RadComboBoxSelectedIndexChangedEventArgs returns an error for the new value and sometimes the text is correct

My version of telerik is : 2013.2.717.35
0
ADAPT
Top achievements
Rank 2
answered on 20 Feb 2014, 08:13 PM
Well I hate to admit I overlooked a mistake I made in my class file. The following function is used to grab the carrier info and I left out the "str = r.String" part of the array. Whoooops! :) If you are still having the same issue Patrice, let me know and I will help.

​ //Return a list of all Cell Phone Carriers
public Array ReturnCarriers()
{
try
{
var result = from r in VEPS.CellPhoneCarriers
select new { Carrier = r.Carrier, str = r.String };

return result.ToArray();
}
catch (Exception ex)
{
_IsError = true;
_ErrorMsg = ex.Message;
return null;
}
}
Tags
ComboBox
Asked by
ADAPT
Top achievements
Rank 2
Answers by
Shinu
Top achievements
Rank 2
ADAPT
Top achievements
Rank 2
Patrice
Top achievements
Rank 1
Share this question
or