I make a multi column combo box. if we type in that combobox then only matched values will return. So far so good but when i want to select some specific element on button click event by setting selectedvalue property then it does not show that value in the combo box. my html and c# code is given below:
<telerik:RadScriptManager ID="RadScriptManager1" runat="server">
</telerik:RadScriptManager>
<telerik:RadComboBox ID="RadComboBox1" runat="server" Skin="Vista" Height="190px"
Width="420px" MarkFirstMatch="true" EnableLoadOnDemand="true"
HighlightTemplatedItems="true" OnClientItemsRequested="UpdateItemCountField"
OnDataBound="RadComboBox1_DataBound" OnItemDataBound="RadComboBox1_ItemDataBound"
OnItemsRequested="RadComboBox1_ItemsRequested"
ontextchanged="RadComboBox1_TextChanged" OnClientKeyPressing="HandkeKeyPress" >
<HeaderTemplate>
<ul>
<li class="col1">Name</li>
<li class="col2">Number</li>
<%--<li class="col3">Title</li>--%>
</ul>
</HeaderTemplate>
<ItemTemplate>
<ul>
<li class="col1">
<%# DataBinder.Eval(Container.DataItem, "Name") %></li>
<li class="col2">
<%# DataBinder.Eval(Container.DataItem, "Number") %></li>
<%--<li class="col3">
<%# DataBinder.Eval(Container.DataItem, "ContactTitle") %></li>--%>
</ul>
</ItemTemplate>
<FooterTemplate>
A total of
<asp:Literal runat="server" ID="RadComboItemsCount" />
items
</FooterTemplate>
</telerik:RadComboBox>
and c# code is:
private DataTable table;
protected void Page_Load(object sender, EventArgs e)
{
DoDataBind();
}
public void DoDataBind()
{
DataTable dt = CreateData();
RadComboBox1.DataSource = dt.DefaultView;
RadComboBox1.DataBind();
}
protected void RadComboBox1_DataBound(object sender, EventArgs e)
{
((Literal)RadComboBox1.Footer.FindControl("RadComboItemsCount")).Text = Convert.ToString(RadComboBox1.Items.Count);
}
private DataTable CreateData()
{
table = new DataTable();
table.Columns.Add("Name", typeof(string));
table.Columns.Add("Number", typeof(int));
table.Rows.Add(new object[] { "one", "1" });
table.Rows.Add(new object[] { "two", "2" });
table.Rows.Add(new object[] { "three", "3" });
table.Rows.Add(new object[] { "four", "4" });
table.Rows.Add(new object[] { "five", "5" });
table.Rows.Add(new object[] { "six", "6" });
return table;
}
protected void RadComboBox1_ItemsRequested(object sender, RadComboBoxItemsRequestedEventArgs e)
{
DataTable dt = new DataTable();
dt.Columns.Add("Name", typeof(string));
dt.Columns.Add("Number", typeof(int));
DataRow[] foundRows;
foundRows = table.Select("Name LIKE '" + e.Text + "%'");
foreach (DataRow dr in foundRows)
{
dt.ImportRow(dr);
}
RadComboBox1.DataSource = dt;
RadComboBox1.DataBind();
}
protected void RadComboBox1_ItemDataBound(object sender, RadComboBoxItemEventArgs e)
{
e.Item.Text = ((DataRowView)e.Item.DataItem)["Name"].ToString() + " (" +((DataRowView)e.Item.DataItem)["Number"].ToString() +")";
e.Item.Value = ((DataRowView)e.Item.DataItem)["Number"].ToString();
}
protected void RadComboBox1_TextChanged(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
RadComboBox1.SelectedValue = 2.ToString();
}
<telerik:RadScriptManager ID="RadScriptManager1" runat="server">
</telerik:RadScriptManager>
<telerik:RadComboBox ID="RadComboBox1" runat="server" Skin="Vista" Height="190px"
Width="420px" MarkFirstMatch="true" EnableLoadOnDemand="true"
HighlightTemplatedItems="true" OnClientItemsRequested="UpdateItemCountField"
OnDataBound="RadComboBox1_DataBound" OnItemDataBound="RadComboBox1_ItemDataBound"
OnItemsRequested="RadComboBox1_ItemsRequested"
ontextchanged="RadComboBox1_TextChanged" OnClientKeyPressing="HandkeKeyPress" >
<HeaderTemplate>
<ul>
<li class="col1">Name</li>
<li class="col2">Number</li>
<%--<li class="col3">Title</li>--%>
</ul>
</HeaderTemplate>
<ItemTemplate>
<ul>
<li class="col1">
<%# DataBinder.Eval(Container.DataItem, "Name") %></li>
<li class="col2">
<%# DataBinder.Eval(Container.DataItem, "Number") %></li>
<%--<li class="col3">
<%# DataBinder.Eval(Container.DataItem, "ContactTitle") %></li>--%>
</ul>
</ItemTemplate>
<FooterTemplate>
A total of
<asp:Literal runat="server" ID="RadComboItemsCount" />
items
</FooterTemplate>
</telerik:RadComboBox>
and c# code is:
private DataTable table;
protected void Page_Load(object sender, EventArgs e)
{
DoDataBind();
}
public void DoDataBind()
{
DataTable dt = CreateData();
RadComboBox1.DataSource = dt.DefaultView;
RadComboBox1.DataBind();
}
protected void RadComboBox1_DataBound(object sender, EventArgs e)
{
((Literal)RadComboBox1.Footer.FindControl("RadComboItemsCount")).Text = Convert.ToString(RadComboBox1.Items.Count);
}
private DataTable CreateData()
{
table = new DataTable();
table.Columns.Add("Name", typeof(string));
table.Columns.Add("Number", typeof(int));
table.Rows.Add(new object[] { "one", "1" });
table.Rows.Add(new object[] { "two", "2" });
table.Rows.Add(new object[] { "three", "3" });
table.Rows.Add(new object[] { "four", "4" });
table.Rows.Add(new object[] { "five", "5" });
table.Rows.Add(new object[] { "six", "6" });
return table;
}
protected void RadComboBox1_ItemsRequested(object sender, RadComboBoxItemsRequestedEventArgs e)
{
DataTable dt = new DataTable();
dt.Columns.Add("Name", typeof(string));
dt.Columns.Add("Number", typeof(int));
DataRow[] foundRows;
foundRows = table.Select("Name LIKE '" + e.Text + "%'");
foreach (DataRow dr in foundRows)
{
dt.ImportRow(dr);
}
RadComboBox1.DataSource = dt;
RadComboBox1.DataBind();
}
protected void RadComboBox1_ItemDataBound(object sender, RadComboBoxItemEventArgs e)
{
e.Item.Text = ((DataRowView)e.Item.DataItem)["Name"].ToString() + " (" +((DataRowView)e.Item.DataItem)["Number"].ToString() +")";
e.Item.Value = ((DataRowView)e.Item.DataItem)["Number"].ToString();
}
protected void RadComboBox1_TextChanged(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
RadComboBox1.SelectedValue = 2.ToString();
}