
Hello,
I have ComboBox:
<telerik:RadComboBox ID="RadComboBox_Branze" runat="server" DataTextField="NAZWA_BRANZA" DataValueField="idTB_BRANZA" EnableLoadOnDemand="True" OnItemsRequested="RadComboBox_Branze_ItemsRequested" Width="300px" ><CollapseAnimation Duration="200" Type="OutQuint" /></telerik:RadComboBox>
In properties of RadComboBox I set:
DataTextField="businesslinename"
DataValueField="id_businessline"
where businesslinename is string value and id_businessline is int value, both retrieved from database
C# method to fill combo:
protected
void RadComboBox_Branze_ItemsRequested(object o, RadComboBoxItemsRequestedEventArgs e)
{
if (e.Text.Length > 3)
{
RadComboBox combo = (RadComboBox)o;
combo.Items.Clear();
string sql = "select * from tb_branza where nazwa_branza like '%" + e.Text + "%' AND idTB_JEZYK=1";
//SqlDataSource1
SqlDataAdapter adapter = new SqlDataAdapter(sql, SqlDataSource1.ConnectionString.ToString());
DataTable data = new DataTable();
adapter.Fill(data);
try
{
int itemsPerRequest = 100;
int itemOffset = e.NumberOfItems;
int endOffset = itemOffset + itemsPerRequest;
if (endOffset > data.Rows.Count)
{
endOffset = data.Rows.Count;
}
if (endOffset == data.Rows.Count)
{
e.EndOfItems =
true;
}
else
{
e.EndOfItems =
false;
}
for (int i = itemOffset; i < endOffset; i++)
{
RadComboBox_Branze.Items.Add(
new RadComboBoxItem(data.Rows[i]["nazwa_branza"].ToString(), data.Rows[i]["nazwa_branza"].ToString()));
}
if (data.Rows.Count > 0)
{
e.Message =
String.Format("Items <b>1</b>-<b>{0}</b> out of <b>{1}</b>", endOffset.ToString(), data.Rows.Count.ToString());
}
else
{
e.Message =
"No matches";
}
}
catch
{
e.Message =
"No matches";
}
}
}
I have got Button to submit method:
protected void btn_DodajBranze_Click(object sender, EventArgs e)
{
TextBox1.Text = RadComboBox_Branze.SelectedValue;
//DodajBranze(id_zamowienie_dns);
}
The problem is that I get DataTextField="businesslinename" instead DataValueField="id_businessline" into my TextBox1. How to retrieve a value from RadComboBox instead of text.
Best Regards
Dariusz TomoĊ
16 Answers, 1 is accepted
I have reviewed your code and notice the following things.
1.In your aspx definition you already have set the DataTextField and the DataValueField properties - DataTextField="NAZWA_BRANZA" DataValueField="idTB_BRANZA"
2.When you load items on demand you add them with text and value form the NAZWA_BRANZA again
new RadComboBoxItem(data.Rows[i]["nazwa_branza"].ToString(), data.Rows[i]["nazwa_branza"].ToString()));
Could you explain more clear how do you set DataTextField="businesslinename"
DataValueField="id_businessline" and which fields you want to use - businesslinename and id_businessline or
NAZWA_BRANZA and idTB_BRANZA?
However I suggest you change the line above like follows:
new RadComboBoxItem(data.Rows[i]["nazwa_branza"].ToString(), data.Rows[i]["idTB_BRANZA"].ToString()));
and let us known how this goes.
Hope this helps.
Regards, Rosi
the Telerik team
Check out Telerik Trainer, the state of the art learning tool for Telerik products.

Even though my explanation was awkward you still get by to help me.
The clue was the line:
However I suggest you change the line above like follows:
new RadComboBoxItem(data.Rows[i]["nazwa_branza"].ToString(), data.Rows[i]["idTB_BRANZA"].ToString()));
and let us known how this goes.
Thank you.
Darek

When submitting, we gets the descriptive texts instead of the codes.
Regards,
Simon
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.

foreach (DataRow dr in drArr) |
{ |
rcb.Items.Add(new RadComboBoxItem(dr["textField"].ToString(), dr["valueField"].ToString())); |
} |
Or, if the same, we translated the commands for the default DropDownList to RadComboBox... and the submit behaviour is quite different.
Best wishes,
Simon
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.

private RadComboBox CrearCampoCombo(string id, bool dinamico, string codigoCombo, bool required, object defValue) |
{ |
RadComboBox rcb = new RadComboBox(); |
rcb.ID = id; |
rcb.Width = Unit.Pixel(150); |
if (!required) |
{ |
rcb.Items.Add(new RadComboBoxItem("", "")); |
} |
DataRow[] drArr = wc.GetDropDownList(dinamico, codigoCombo, idioma, Page.User.Identity.Name); |
foreach (DataRow dr in drArr) |
{ |
rcb.Items.Add(new RadComboBoxItem(dr["texto"].ToString(), dr["valor"].ToString())); |
if (defValue != null && defValue.Equals(dr["valor"])) |
{ |
rcb.Items[rcb.Items.Count - 1].Selected = true; |
} |
} |
return rcb; |
} |
where dr["texto"] contains the text the user can read and dr["valor"] contains the values to send to the server if selected.
Kind regards,
Simon
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.

texto: "Following"; value: "FOL"
texto: "Preceeding"; value: "PRE"
texto: "Modified following"; value: "MFO"
texo: "Modified preceeding"; value: "MPR"
Regards,
Simon
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.

Here the code referencing the sample combo I showed before.
Sys.Application.add_init(function() { |
$create(Telerik.Web.UI.RadComboBox, {"_dropDownWidth":0,"_height":0,"_skin":"Blues","_text":"Modified Following","_uniqueId":"DefMaint$convFechas","_value":"MFO","_virtualScroll":false,"clientStateFieldID":"DefMaint_convFechas_ClientState","collapseAnimation":"{\"type\":12,\"duration\":200}","enabled":false,"itemData":[{"value":"FOL"},{"value":"MFO","selected":true},{"value":"MPR"},{"value":"PRE"}],"selectedIndex":1}, null, null, $get("DefMaint_convFechas")); |
}); |
<td style="text-align:Left;"> |
<span id="DefMaint_convFechas_label">Conv. fechas</span> |
</td> |
<td style="text-align:Left;"> |
<div id="DefMaint_convFechas" class="RadComboBox RadComboBox_Blues " style="width:160px;display:inline;zoom:1;"> |
<table class="rcbDisabled" cellpadding="0" cellspacing="0" summary="combobox" border="0" style="border-width:0;table-layout:fixed;border-collapse:collapse;width:100%"> |
<tr> |
<td class="rcbInputCell rcbInputCellLeft" style="margin-top:-1px;margin-bottom:-1px;width:100%;"><input value="Modified Following" class="rcbInput" id="DefMaint_convFechas_Input" title="Conv. fechas" name="DefMaint$convFechas" style="display:block;text-decoration:;" type="text" disabled="disabled" readonly="readonly"></input> |
</td> |
<td class="rcbArrowCell rcbArrowCellRight" style="margin-top:-1px;margin-bottom:-1px;"><a id="DefMaint_convFechas_Arrow" style="overflow: hidden;display: block;position: relative;outline: none;">select</a> |
</td> |
</tr> |
</table> |
<div class="rcbSlide" style="z-index:6000;"> |
<div id="DefMaint_convFechas_DropDown" class="RadComboBoxDropDown_Blues" style="float:left;display:none;"> |
<div class="rcbScroll rcbWidth" style="width:100%;"> |
<ul class="rcbList" style="list-style:none;margin:0;padding:0;zoom:1;"> |
<li class="rcbItem ">Following</li> |
<li class="rcbItem ">Modified Following</li> |
<li class="rcbItem ">Modified Preceeding</li> |
<li class="rcbItem ">Preceeding</li> |
</ul> |
</div> |
</div> |
</div> |
<input id="DefMaint_convFechas_ClientState" name="DefMaint_convFechas_ClientState" type="hidden" /> |
</div> |
</td> |
Hope this would help.
Sincerely yours,
Simon
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.

At current we use the Q1 of 2010, and I'm still having the same problem, when submitting RadComboBox sends the text field, not the value field.
It is normal to see in the submitted form fields the RadComboBox' text and not its value. The latter is submitted through the Client State field of RadComboBox. Then the control parses this field and extracts the Value so that it is later accessible through the SelectedValue property.
Can you please restate what exactly is the problem you are experiencing? Can you also open a support ticket and send us a sample project, which shows the problem (and mention this forum thread as well)?
We will respond to both places once we find the solution.
Thank you in advance for your co-operation and understanding.
All the best,
Simon
the Telerik team

Thx.
The RadComboBox and ASP.NET DropDownList are absolutely different controls - they differ by design, implementation and behaviour.
The DropDownList is not an AJAX control, does not have client-side functionality and it renders as a "<select>" - that is why you are able to get the selected value.
The RadComboBox renders as an "<input>" so it is normal to obtain the text entered in this input via Request object.
That is why you have to use the SelectedValue of the RadComboBox in order to get the selected value.
Regards,
Kalina
the Telerik team