ComboBox SelectedValue Null or ""

5 posts, 0 answers
  1. TommyBoy
    TommyBoy avatar
    22 posts
    Member since:
    Oct 2011

    Posted 19 Feb 2014 Link to this post

    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?
  2. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 19 Feb 2014 in reply to TommyBoy Link to this post

    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.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. TommyBoy
    TommyBoy avatar
    22 posts
    Member since:
    Oct 2011

    Posted 19 Feb 2014 in reply to Shinu Link to this post

    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.
  5. Patrice
    Patrice avatar
    1 posts
    Member since:
    Feb 2014

    Posted 20 Feb 2014 in reply to TommyBoy Link to this post

    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
  6. TommyBoy
    TommyBoy avatar
    22 posts
    Member since:
    Oct 2011

    Posted 20 Feb 2014 in reply to Patrice Link to this post

    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;
    }
    }
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017