Promlem with adding a blank row.

5 posts, 1 answers
  1. Andy Green
    Andy Green avatar
    342 posts
    Member since:
    Aug 2008

    Posted 14 May 2015 Link to this post

    Hi

    This is my code to bind data to a RadComboBox:

    With ddlFutureCode
    .Items.Clear()
    .Items.Add(New RadComboBoxItem("", 0))
    .DataSource = l_ds.Tables(1)
    .DataTextField = "Name"
    .DataValueField = "Value"
    .DataBind()
    End With

     

    It works fine, and places a blank row at the top if no selection is to be made. However:

    With this code )setting a default tot blank row disappears so if the default value isn't required ist not possible to select a blank row.

    With ddlFutureCode
     .Items.Clear()
    .Items.Add(New RadComboBoxItem("", 0))
    .DataSource = l_ds.Tables(1)
    .DataTextField = "Name"
    .DataValueField = "Value"
    .DataBind()

    End With
    ddlFutureCode.SelectedItem.Text = FutureCode

     Andy

     

     

  2. Aneliya Petkova
    Admin
    Aneliya Petkova avatar
    207 posts

    Posted 18 May 2015 Link to this post

    Hi Andy,

    Please try the sample page I attached to this thread and modify it in order to show me the issue you are facing, because I am not sure I understand you correctly. Here you may find a video demonstrating how the RadComboBox is behaving at my side.

    Regards,
    Aneliya Petkova
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Andy Green
    Andy Green avatar
    342 posts
    Member since:
    Aug 2008

    Posted 18 May 2015 in reply to Aneliya Petkova Link to this post

    Hi Aneliya

    If you change your code to match this you will see the problem:

    With ddlFutureCode
    .Items.Clear()
    .Items.Add(New RadComboBoxItem("", 0))
    .Items.Add(New RadComboBoxItem("1", 1))
    .Items.Add(New RadComboBoxItem("FutureCode", 2))
    .DataBind()
    End With
    'ddlFutureCode.SelectedIndex = 2
    ddlFutureCode.SelectedItem.Text = "FutureCode"

    form1.Controls.Add(ddlFutureCode)

    I'm not using Selected Index as I wont know the index values of the required field in the dataset.

    Andy

     

  5. Answer
    Aneliya Petkova
    Admin
    Aneliya Petkova avatar
    207 posts

    Posted 19 May 2015 Link to this post

    Hi Andy,

    Could you please explain in more details what exactly you need to achieve, because I am still not sure I understand you correctly?

    Please note that when you are using the code below, you are overriding the Text of the Selected Item - in your case this is the first item in the RadCombomboBox(with the empty text):
    ddlFutureCode.SelectedItem.Text = "FutureCode"

    If you want to select an item from the RadComboBox by its Text, you can use the following code instead:
    ddlFutureCode.FindItemByText("FutureCode").Selected = True

    So the changed VB code should look like the following:
    Dim ddlFutureCode As New RadComboBox
     
    With ddlFutureCode
        .Items.Clear()
        .Items.Add(New RadComboBoxItem("", 0))
        .Items.Add(New RadComboBoxItem("1", 1))
        .Items.Add(New RadComboBoxItem("FutureCode", 2))
        .DataBind()
    End With
     
    ddlFutureCode.FindItemByText("FutureCode").Selected = True
     
    form1.Controls.Add(ddlFutureCode)


    Regards,
    Aneliya Petkova
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  6. Andy Green
    Andy Green avatar
    342 posts
    Member since:
    Aug 2008

    Posted 19 May 2015 in reply to Aneliya Petkova Link to this post

    Thanks Aneliya

    This is what I was missing:

    ddlFutureCode.FindItemByText("FutureCode").Selected = True

    Andy

Back to Top
UI for ASP.NET Ajax is Ready for VS 2017