I am trying to implement a load on demand scenario for a RadComboBox but am struggling to get it to work with multi columns and attributes.
Here is the code for my RadComboBox
<telerik:RadComboBox ID="ddlStudents" |
EnableViewState="false" |
runat="server" |
EnableVirtualScrolling="true" |
ShowMoreResultsBox="true" |
EnableLoadOnDemand="true" |
OnClientFocus="OnClientFocus" |
EnableItemCaching="true" |
HighlightTemplatedItems="true" |
EmptyMessage="Select a student or start typing their name" |
ExpandAnimation-Duration="150" |
IsCaseSensitive="false" |
CollapseAnimation-Duration="9" |
Skin="Default" |
DataValueField="StudentId" |
DataTextField="CombinedName" |
ToolTip="Select a student from the drop down list or start typing their name/ID to return only those students matching your criteria." |
MaxHeight="250px" |
Width="100%"> |
<HeaderTemplate> |
<ul class="RadComboBoxDefault"> |
<li class="RadComboBoxColumn1">Year</li> |
<li class="RadComboBoxColumn2">Student</li> |
<li class="RadComboBoxColumn3">Status</li> |
</ul> |
<br style="clear: left" /> |
</HeaderTemplate> |
<ItemTemplate> |
<ul class="RadComboBoxDefault"> |
<li class="RadComboBoxColumn1"> |
<%# DataBinder.Eval(Container, "Attributes[\"Year\"]")%></li> |
<li class="RadComboBoxColumn2"> |
<%# DataBinder.Eval(Container, "Attributes[\"CombinedName\"]")%> |
</li> |
<li class="RadComboBoxColumn3"> |
<%#DataBinder.Eval(Container, "Attributes[\"StudentStatus\"]") %> |
</li> |
</ul> |
<br style="clear: left" /> |
</ItemTemplate> |
<WebServiceSettings Method="GetStudents" Path="TestingPageMethods.aspx" /> |
</telerik:RadComboBox> |
And my code-behind:
[WebMethod] |
public static RadComboBoxData GetStudents(RadComboBoxContext context) |
{ |
VList<StudentDTO> data = GetStudents(); |
if (context.Text != "") |
{ |
data.ApplyFilter(delegate(StudentDTO s) |
{ |
return s.CombinedName.ToLower().Contains(context.Text.ToLower()); |
} |
); |
} |
RadComboBoxData comboData = new RadComboBoxData(); |
int itemOffset = context.NumberOfItems; |
int endOffset = Math.Min(itemOffset + 100, data.Count); |
comboData.EndOfItems = endOffset == data.Count; |
List<RadComboBoxItemData> result = new List<RadComboBoxItemData>(endOffset - itemOffset); |
for (int i = itemOffset; i < endOffset; i++) |
{ |
RadComboBoxItemData itemData = new RadComboBoxItemData(); |
itemData.Text = data[i].CombinedName; |
itemData.Attributes.Add("CombinedName", data[i].CombinedName); |
itemData.Value = data[i].StudentId; |
itemData.Attributes.Add("StudentStatus", data[i].StudentStatus); |
itemData.Attributes.Add("Year", data[i].StudentYear); |
result.Add(itemData); |
} |
comboData.Message = GetStatusMessage(endOffset, data.Count); |
comboData.Items = result.ToArray(); |
return comboData; |
} |
The call to the PageMethod is working fine and the data is being populated in the RadComboBox, but the item template is ignored. All I am seeing is the returned Text property of the RadComboBoxItemData item. The documentation states that for attributes to work the way I am trying to use them, the RadComboBoxItem must call it's DataBind() method. Obviously this isn't happening on the web service request. Is there a way of doing this using LoadOnDemand and PageMethods/WebServices ?
Thanks
26 Answers, 1 is accepted
The page Templates are not supported when you use a web service to populate RadComboBox with data.
However you can use both LoadOnDemand and Templates at the same time - please take a look at this example.
Please let me know if you need further assistance.
Greetings,
Kalina
the Telerik team
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 Public Issue Tracking system and vote to affect the priority of the items.
We were doing something similar, but we've run into a snag when an additional requirement was added. Before I get to that, I wanted to point out that using the OnItemsRequested event can't be used as the list needs to be cleared with each request. This is why we are using the web service or WCF. The additional requirement that we have requires that we send additional data/parameters to the web service (i.e. max count and other filter information). Is there a way that we can add items to the RadComboBoxContext object being sent to the web service? The data that we need to send is stored in hidden fields on the form page.
Thanks,
Bill
Thank you for the clarification.
About clearing items on each request - you can clear items at server side with RadComboBox.Items.Clear() method, and at client side with the corresponding clearItems() method.
To pass additional information to the server you may follow this approach :
- On the client side, use OnClientItemsRequesting event to set attributes of the context object that is passed to the server along with the request for items:
<
script
type
=
"text/javascript"
>
function OnClientItemsRequestingHandler(sender, eventArgs) {
var context = eventArgs.get_context();
var hiddenField = document.getElementById("<%= hiddenField1.ClientID %>");
context["SomeString"] = eventArgs.get_text();
context["ExampleValue"] = hiddenField.value;
}
</
script
>
<
body
>
<
form
id
=
"form1"
runat
=
"server"
>
<
telerik:RadScriptManager
runat
=
"server"
ID
=
"RadScriptManager1"
/>
<
div
>
<
telerik:RadComboBox
ID
=
"RadComboBox1"
runat
=
"server"
Height
=
"100px"
Width
=
"220px"
ShowMoreResultsBox
=
"true"
MarkFirstMatch
=
"true"
EnableLoadOnDemand
=
"True"
OnClientItemsRequesting
=
"OnClientItemsRequestingHandler"
>
<
WebServiceSettings
Path
=
"LoadItemsWebService.asmx"
Method
=
"GetCompanyNames"
/>
</
telerik:RadComboBox
>
<
asp:HiddenField
Value
=
"1"
ID
=
"hiddenField1"
runat
=
"server"
/>
</
div
>
</
form
>
</
body
>
- When the context object is passed to the Web service method you can retrieve the attributes like this:
[WebMethod]
public
RadComboBoxData GetCompanyNames(RadComboBoxContext context)
{
int
example = Convert.ToInt32(context[
"ExampleValue"
]);
string
filterString = context[
"SomeString"
].ToString();
string
contextText = context.Text;
// you can find full method at the sample page
}
More details you can find at example page attached.
Regards,
Kalina
the Telerik team
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 Public Issue Tracking system and vote to affect the priority of the items.
I'll give that a try. I did try using the RadComboBox.Items.Clear() method, but I think that it may be bugged as it didn't clear the combo box drop down length. If I remember correctly the items seemed to be cleared, but the item count wasn't. This resulted in a list that kept getting longer and longer, padded with empty/blank items.
Thanks,
Bill
Did you succeeded to implement the populating the RadComboBox with webservice and sending additional data to the server setting the context attributes?
Feel free to contact us if you need further assistance.
Kind regards,
Kalina
the Telerik team
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 Public Issue Tracking system and vote to affect the priority of the items.
More details about Load On Demand and our new feature - Automatic Load On Demand you can find at this online demo.
Greetings,
Kalina
the Telerik team
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 Public Issue Tracking system and vote to affect the priority of the items.
Could you please compare your implementation with the online demo?
Could you find any differences?
Greetings,
Kalina
the Telerik team
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 Public Issue Tracking system and vote to affect the priority of the items.
I am trying to implement a load on demand scenario for a RadComboBox but am struggling to get it to work with multi columns and attributes.
Here is the code for my RadComboBox:
<YDSC:ExRadComboBox ID="cmbFinanceEmpCode" runat="server" DropDownWidth="500px" Height="150px"
DataTextField="Name" DataValueField="GUID" EnableLoadOnDemand="True" ShowMoreResultsBox="true"
EnableVirtualScrolling="true" OnItemsRequested="cmbFinanceEmpCode_ItemsRequested"
OnClientKeyPressing="cmbFinanceEmpCode_ClientKeyPressing">
<HeaderTemplate>
<ul>
<li class="col1">姓名</li>
<li class="col2">唯一标识</li>
<li class="col3">部门</li>
</ul>
</HeaderTemplate>
<ItemTemplate>
<ul>
<li class="col1">
<%# DataBinder.Eval(Container.DataItem, "Name")%></li>
<li class="col2">
<%# DataBinder.Eval(Container.DataItem, "GUID")%></li>
<li class="col3">
<%# DataBinder.Eval(Container.DataItem, "DeptName")%></li>
</ul>
</ItemTemplate>
</YDSC:ExRadComboBox>
protected void cmbFinanceEmpCode_ItemsRequested(object sender, RadComboBoxItemsRequestedEventArgs e)
{
DataTable data = GetEmployeeInfoData(e.Text);
int itemOffset = e.NumberOfItems;
int endOffset = Math.Min(itemOffset + ItemsPerRequest, data.Rows.Count);
e.EndOfItems = endOffset == data.Rows.Count;
for (int i = itemOffset; i < endOffset; i++)
{
RadComboBoxItem item = new RadComboBoxItem(data.Rows[i]["Name"].ToString(), data.Rows[i]["GUID"].ToString());
item.Attributes["DeptCode"] = data.Rows[i]["DeptCode"].ToString();
item.Attributes["DeptName"] = data.Rows[i]["DeptName"].ToString();
cmbFinanceEmpCode.Items.Add(item);
}
e.Message = GetStatusMessage(endOffset, data.Rows.Count);
}
}
My problem similar the problem of TomL。You let us see examples。But the examples is not like my current situation。
My current situation:
1、I need Multi columns show
2、the number of Data is so huge。so I must Use "cmbFinanceEmpCode.Items.Add(item); "。but you examples is use "RadComboBox.DataBind()"。if i do like the Example,the Efficiency is low
Thanks
Please note that Container.DataItem is a runtime alias for the DataItem for this specific item in the databound control. That is why you need to databind the RadComboBoxItems.
To display the custom attribute of RadComboBoxItem you have to use
<%# DataBinder.Eval(Container, "Attributes['DeptName']")%>
<%# DataBinder.Eval(Container.DataItem, "DeptName")%> .
Please take a look at this online demo - the "Products" RadComboBox there is a good example for multicolumn layout with usage of custom attributes.
All the best,
Kalina
the Telerik team
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 Public Issue Tracking system and vote to affect the priority of the items.
Have any separate radcombo box like change skin combo box of Telerik demo page ( http://demos.telerik.com/aspnet-ajax/combobox/examples/default/defaultcs.aspx ) ?
If yes tell me the radcombobox type.
Regards
Joseph.S
I am afraid that the "Change Skin" control is not a RadComboBox but a skin managing control created for internal use.
You can achieve similar appearance using templates - please take a look at the second RadComboBox ("Multiple rows and columns") at this online demo.
All the best,
Kalina
the Telerik team
Thanks for your reply. I'm able to create combo box like telerik demo page using Radmulti column control.
Regards
Joseph
I am afraid that Templates are not supported when you use a web service to populate RadComboBox with data.
You can use both Load On Demand and Templates if you implement a server-side ItemsRequested event handler - please take a look at this online demo.
Kind regards,
Kalina
the Telerik team
I wanted to use the radcombobox control and load the list on demand using a webservice based on user's search string. I was hoping to use either of the two options below
1.I have five fields that I can retrieve from the webservice and show it to the user using multi-column format. I was hoping to use a template for it but I guess that is not possible with a webservice?
2. I want to display the first two fields (concatnated) in the dropdownlist (like firsname, lastname) but show the remaining three fields (like email address: xxx; jobtitle:aaa dpt: zzz) as tooltips when the user hover over the list in the drop down. Since the dropdown list is populated using the webservice (only two fields) how can i use the remaining three fields retruned by the webserice as a tooltip for each loaded items in the dropdown? I thought of putting all the five fields in the Text property of the radcomboboxdataitem but that is too bulky.
Any Ideas?
Thanks,
The RadComboBox ItemTemplate is instantiated at server-side - that is why it is not possible to use it when you populate the control via Load On Demand from WebService.
I can suggest you use the RadComboBox Client Templates.
All the best,
Kalina
the Telerik team
I just about have a Load on Demand RadComboBox working with a multi-column template - with one problem.
The contents of my drop down refresh based on what the user types in - so as they type in letters the box only displays values that start with what they have typed. This works fine - UNLESS what is typed returns only 1 result. If they type letters in that result in only one result to be displayed in the drop down - then the dropdown instead shows NOTHING. **With more testing what I have realized is that the 1 record is actually there - the drop down just doesn't expand down far enough to see it. I have the same problem if the typed letters return 2 results only - the drop down opens far enough to display 1 item only, making it appears as if there is only 1 option - and the user has to scroll down to get to the 2nd. Why when the results are only 1 or 2 rows is the dropdown now dropping down far enough to show them all??
My RadcomboBox is as follows:
<
telerik:RadComboBox
ID
=
"rcbRetailProducer"
runat
=
"server"
Width
=
"224px"
EmptyMessage
=
" "
EnableLoadOnDemand
=
"true"
ShowMoreResultsBox
=
"true"
EnableVirtualScrolling
=
"true"
DropDownWidth
=
"450px"
>
<
HeaderTemplate
>
<
table
cellpadding
=
"0"
cellspacing
=
"0"
style
=
"width: 450px"
>
<
tr
>
<
td
style
=
"width: 225px"
><
strong
>Producer</
strong
></
td
>
<
td
style
=
"width: 75px"
><
strong
>ID</
strong
></
td
>
<
td
style
=
"width: 100px"
><
strong
>City</
strong
></
td
>
<
td
style
=
"width: 50px"
><
strong
>State</
strong
></
td
>
</
tr
>
</
table
>
</
HeaderTemplate
>
<
ItemTemplate
>
<
table
cellpadding
=
"0"
cellspacing
=
"0"
style
=
"width: 450px"
>
<
tr
>
<
td
style
=
"width: 225px"
>
<%# DataBinder.Eval(Container, "Text") %>
</
td
>
<
td
style
=
"width: 75px"
>
<%# DataBinder.Eval(Container, "Attributes['ID']") %>
</
td
>
<
td
style
=
"width: 100px"
>
<%# DataBinder.Eval(Container, "Attributes['City']") %>
</
td
>
<
td
style
=
"width: 50px"
>
<%# DataBinder.Eval(Container, "Attributes['State']") %>
</
td
>
</
tr
>
</
table
>
</
ItemTemplate
>
</
telerik:RadComboBox
>
And in my code behind:
Private Sub rcbRetailProducer_ItemsRequested(ByVal o As Object, ByVal e As Telerik.Web.UI.RadComboBoxItemsRequestedEventArgs) Handles rcbRetailProducer.ItemsRequested
Dim retailDS As New DataSet
Dim ItemsPerRequest As Integer = 25
MyBase.ErrHdlr(DBLists.GetRetailProducersDDL(retailDS, e.Text))
'This loads the retailDS dataset with the results of a stored procedure call
Dim itemOffset As Integer = e.NumberOfItems
Dim endOffset As Integer = Math.Min(itemOffset + ItemsPerRequest, retailDS.Tables(0).Rows.Count)
e.EndOfItems = endOffset = retailDS.Tables(0).Rows.Count
For i As Integer = itemOffset To endOffset - 1
Dim item As New RadComboBoxItem
item.Text = retailDS.Tables(0).Rows(i)("Name").ToString()
item.Value = retailDS.Tables(0).Rows(i)("Value").ToString()
item.Attributes.Add("ID", retailDS.Tables(0).Rows(i)("ID").ToString())
item.Attributes.Add("City", retailDS.Tables(0).Rows(i)("City").ToString())
item.Attributes.Add("State", retailDS.Tables(0).Rows(i)("State").ToString())
Me.rcbRetailProducer.Items.Add(item)
item.DataBind()
Next
End Sub
It seems the drop-down is dropping down to the number of items MINUS 1 - so when there are only 1 or 2 items, this is not desired. How can I change this??
Would you provide us with a screenshot, demonstrating the faced issue? In addition would you specify the used version and under which browser are you encountering the problem?
Kind regards,
Nencho
the Telerik team
I am attaching 3 images, designated with "3_items", "2_items", and "1_item" as part of their file names. Notice that when there are 3 items in the drop down, you can only see 2 - rest assured the 3rd is there if I scroll down. Same for the others - in the image titled radcombo_2_items there are indeed 2 items, but you can only see 1 - and in the radcombo_1_item there is actually an item, but you can't see it at all and it is almost impossible to scroll since the dropdown has expanded so little.
I did find that I can solve this by including a "Height" attribute in the <telerik:RadComboBox> tag and setting a static height - but it seems there should be a built in minimum height so that users can allow the box to dynamically resize its drop-down height without it getting too small to work with when the item count gets small.
Thanks!
Then faced issue is originated by the configured layout of the DropDown. The set Width of the DropDown, matches the width of the Table in the ItemTemplate, which forces a scroll bar to appear in the DropDown. Therefor when only one item is rendered in the DropDown it is hidden from the scroll bar. I would suggest you to decrease the table's width or increase the DropDownWidth property of the RadComboBox.
In the following manner for example :
<
ItemTemplate
>
<
table
cellpadding
=
"0"
cellspacing
=
"0"
style
=
"width: 440px"
>
<
tr
>
<
td
style
=
"width: 225px"
>
<%# DataBinder.Eval(Container, "Text") %>
</
td
>
<
td
style
=
"width: 75px"
>
<%# DataBinder.Eval(Container, "Attributes['ID']") %>
</
td
>
<
td
style
=
"width: 100px"
>
<%# DataBinder.Eval(Container, "Attributes['City']") %>
</
td
>
<
td
style
=
"width: 50px"
>
<%# DataBinder.Eval(Container, "Attributes['State']") %>
</
td
>
</
tr
>
</
table
>
</
ItemTemplate
>
Kind regards,
Nencho
the Telerik team
We are using multi column Radcombobox load on demand,its working fine with item requested event.
but while editing opening drop down preselected text not showing,attchd screen shot shows issue
below is the code
<telerik:RadComboBox ID="RcbAccountCode" runat="server" EmptyMessage="Select a Code"
OnClientFocus="ClientFocus" CausesValidation="false" EnableLoadOnDemand="True"
Height="150px" EnableVirtualScrolling="false" ShowMoreResultsBox="false" MarkFirstMatch="true"
HighlightTemplatedItems="true" OnClientItemsRequested="UpdateItemCountField"
AutoPostBack="true" OnItemsRequested="InvoiceDetail_AccountCode1_ItemsRequested"
Width="400px" OnDataBound="InvoiceDetail_AccountCode_DataBound" OnSelectedIndexChanged="InvoiceDetail_AccountCode1_OnSelectedIndexChanged">
<HeaderTemplate>
<table style="width: 100%">
<tr style="width: 100%">
<td style="width: 100px" align="left">
Code
</td>
<td align="left">
Name
</td>
</tr>
</table>
</HeaderTemplate>
<ItemTemplate>
<table style="width: 100%">
<tr style="width: 100%">
<td style="width: 100px" align="left">
<%# DataBinder.Eval(Container, "Attributes[\"code\"]")%>
</td>
<td align="left">
<%# DataBinder.Eval(Container, "Attributes[\"name\"]")%>
</td>
</tr>
</table>
</ItemTemplate>
<FooterTemplate>
A total of
<asp:Literal runat="server" ID="RadComboItemsCount" />
items
</FooterTemplate>
</telerik:RadComboBox>
------------------------------------------------------------------------
below is the pre selected code while edit
RadComboBoxItem itemData = new RadComboBoxItem();
itemData.Text = ds1.Tables[0].Rows[0]["name"].ToString();
itemData.Attributes.Add("name", ds1.Tables[0].Rows[0]["name"].ToString());
itemData.Value = ds1.Tables[0].Rows[0]["code"].ToString();
itemData.Attributes.Add("code", ds1.Tables[0].Rows[0]["code"].ToString());
RcbAccCode.Items.Insert(0, itemData);
RcbAccCode.SelectedIndex = 0;
i want to show preselected text in dropdown while opening.please let me know how to fix this.
Thanks
Karthik
Please have a look into this online demo which works as expected for me. Please try to replicate the issue in this online demo or provide a sample code where I can replicate the issue for further help.
Thanks,
Shinu.
Thanks for your response.
Multi column radcombo box load on demand is working as expected .This combo is used in rad grid edit form.but only issue i have is while edit pre selected value is showing properly. when i remove the preselected text and open drop down item is there but not showing text(see attached screenshot from previous post)
below is the code
aspx code
<telerik:RadComboBox ID="RcbAccountCode" runat="server" EmptyMessage="Select a Code"
OnClientFocus="ClientFocus" CausesValidation="false" EnableLoadOnDemand="True"
Height="150px" EnableVirtualScrolling="false" ShowMoreResultsBox="false" MarkFirstMatch="true"
HighlightTemplatedItems="true" OnClientItemsRequested="UpdateItemCountField"
AutoPostBack="true" OnItemsRequested="InvoiceDetail_AccountCode1_ItemsRequested"
Width="400px" OnDataBound="InvoiceDetail_AccountCode_DataBound" OnSelectedIndexChanged="InvoiceDetail_AccountCode1_OnSelectedIndexChanged">
<HeaderTemplate>
<table style="width: 100%">
<tr style="width: 100%">
<td style="width: 100px" align="left">
Code
</td>
<td align="left">
Name
</td>
</tr>
</table>
</HeaderTemplate>
<ItemTemplate>
<table style="width: 100%">
<tr style="width: 100%">
<td style="width: 100px" align="left">
<%# DataBinder.Eval(Container, "Attributes[\"code\"]")%>
</td>
<td align="left">
<%# DataBinder.Eval(Container, "Attributes[\"name\"]")%>
</td>
</tr>
</table>
</ItemTemplate>
<FooterTemplate>
A total of
<asp:Literal runat="server" ID="RadComboItemsCount" />
items
</FooterTemplate>
</telerik:RadComboBox>
Below is item requested event
protected void InvoiceDetail_AccountCode1_ItemsRequested(object sender, RadComboBoxItemsRequestedEventArgs e)
{
bool bfilter = true;
DataSet ds = new DataSet();
if (e.Text == "")
{
bfilter = false;
}
RadComboBox RcbAccCode = (RadComboBox)sender;
RcbAccCode.Items.Clear();
ds = LoadAccCode(bfilter, e.Text, RcbAccCode);
int itemOffset = e.NumberOfItems;
int endOffset = Math.Min(itemOffset + ItemsPerRequest, ds.Tables[0].Rows.Count);
e.EndOfItems = endOffset == ds.Tables[0].Rows.Count;
for (int i = itemOffset; i < endOffset; i++)
{
RadComboBoxItem itemData = new RadComboBoxItem();
itemData.Text = ds.Tables[0].Rows[i]["name"].ToString();
itemData.Attributes.Add("name", ds.Tables[0].Rows[i]["name"].ToString());
itemData.Value = ds.Tables[0].Rows[i]["code"].ToString();
itemData.Attributes.Add("code", ds.Tables[0].Rows[i]["code"].ToString());
RcbAccCode.Items.Add(itemData);
}
RcbAccCode.DataBind();
}
below id radgrid databound code
protected void RadGrid1_OnItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e)
{
if (e.Item.IsInEditMode)
{
if (!(e.Item is IGridInsertItem))
{
if (e.Item is GridEditFormItem)
{
RadComboBox RcbAccCode = (RadComboBox)e.Item.FindControl("RcbAccountCode"); if (RcbAccCode != null)
squery = "select * from vw_AcctgCOACode where code ='" + dataItem["Account"].Text + "' ";
ds1 = DBUtils.ExecuteDataset(squery);
if (ds1.Tables[0].Rows.Count > 0)
{
RadComboBoxItem itemData = new RadComboBoxItem();
itemData.Text = ds1.Tables[0].Rows[0]["name"].ToString();
itemData.Attributes.Add("name", ds1.Tables[0].Rows[0]["name"].ToString());
itemData.Value = ds1.Tables[0].Rows[0]["code"].ToString();
itemData.Attributes.Add("code", ds1.Tables[0].Rows[0]["code"].ToString());
RcbAccCode.Items.Insert(0, itemData);
RcbAccCode.SelectedIndex = 0;
}
}
}
}
Thanks
Karthik.A
Please try the sample code snippet which works fine at my end.
ASPX:
<
telerik:RadGrid
ID
=
"RadGrid1"
runat
=
"server"
DataSourceID
=
"SqlDataSource2"
AutoGenerateColumns
=
"false"
AutoGenerateEditColumn
=
"true"
>
<
MasterTableView
>
<
Columns
>
<
telerik:GridBoundColumn
DataField
=
"OrderID"
UniqueName
=
"OrderID"
>
</
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
DataField
=
"CustomerID"
UniqueName
=
"CustomerID"
>
</
telerik:GridBoundColumn
>
<
telerik:GridTemplateColumn
>
<
EditItemTemplate
>
<
telerik:RadComboBox
runat
=
"server"
ID
=
"RadComboBox1"
Height
=
"190px"
Width
=
"420px"
AllowCustomText
=
"true"
MarkFirstMatch
=
"true"
DataSourceID
=
"SqlDataSource1"
EnableLoadOnDemand
=
"true"
HighlightTemplatedItems
=
"true"
OnItemDataBound
=
"RadComboBox1_ItemDataBound"
OnItemsRequested
=
"RadComboBox1_ItemsRequested"
>
<
HeaderTemplate
>
<
ul
>
<
li
class
=
"col1"
>Contact Name</
li
>
<
li
class
=
"col2"
>City</
li
>
<
li
class
=
"col3"
>Title</
li
>
</
ul
>
</
HeaderTemplate
>
<
ItemTemplate
>
<
ul
>
<
li
class
=
"col1"
>
<%# DataBinder.Eval(Container.DataItem, "ContactName") %></
li
>
<
li
class
=
"col2"
>
<%# DataBinder.Eval(Container.DataItem, "City") %></
li
>
<
li
class
=
"col3"
>
<%# DataBinder.Eval(Container.DataItem, "ContactTitle") %></
li
>
</
ul
>
</
ItemTemplate
>
</
telerik:RadComboBox
>
</
EditItemTemplate
>
</
telerik:GridTemplateColumn
>
</
Columns
>
</
MasterTableView
>
</
telerik:RadGrid
>
C#:
protected
void
RadComboBox1_ItemsRequested(
object
sender, RadComboBoxItemsRequestedEventArgs e)
{
//get all customers whose name starts with e.Text
string
sql =
"SELECT * from Customers WHERE ContactName LIKE '"
+ e.Text +
"%'"
;
RadComboBox combo = (RadComboBox)sender;
SqlDataSource1.SelectCommand = sql;
combo.DataBind();
}
protected
void
RadComboBox1_ItemDataBound(
object
sender, RadComboBoxItemEventArgs e)
{
//set the Text and Value property of every item
e.Item.Text = ((DataRowView)e.Item.DataItem)[
"ContactName"
].ToString();
e.Item.Value = ((DataRowView)e.Item.DataItem)[
"CustomerID"
].ToString();
}
Thanks,
Shinu.
I am facing a Problem multi column combo box I want visible a column and his items on condition base ,I have attached a picture ,I am trying last column of combo box header and item not visible
You can use CSS to hide the multiple-column column:
<style>
.col1
{
display: none;
}
</style>
<style>
/* cell index is 1-based not 0-based */
.k-dropdowngrid-popup .k-list-scroller .k-cell:nth-child(2),
.k-dropdowngrid-popup .k-list-scroller .k-cell:nth-child(3),
.k-dropdowngrid-popup .k-list-scroller .k-cell:nth-child(5),
.k-dropdowngrid-popup .k-list-scroller .k-cell:nth-child(6){
display: none;
}
</style>