Hi,
I am using RadCombobox with EnableLoadOnDemand="true" Option , its working fine.I have Clear Button in the same page ,After clicking on Clear Button i need to display default item in combobox.
I saw solution for the same requirement , but thats not working .
Following is Aspx Code :
<telerik:RadComboBox ID="RadComboBox1" runat="server"
EmptyMessage="Select" EnableLoadOnDemand="true"
>
</telerik:RadComboBox>
<asp:Button ID="btnSubmit" runat ="server" Text ="Clear" OnClick ="btnSubmit_click"/>
Following is Csharp Code :
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
DataTable dataTable = CreateDataSource();
foreach (DataRow dataRow in dataTable.Rows)
{
RadComboBoxItem item = new RadComboBoxItem();
item.Text = (string)dataRow["Name"];
item.Value = dataRow["ID"].ToString();
RadComboBox1.Items.Add(item);
item.DataBind();
}
// preselect the second item
//RadComboBox1.SelectedValue = "0";
RadComboBox1.Items[0].Selected = true;
}
}
protected DataTable CreateDataSource()
{
DataTable dataTable = new DataTable();
dataTable.Columns.Add(new DataColumn("ID", typeof(string)));
dataTable.Columns.Add(new DataColumn("Name", typeof(string)));
DataRow dr = dataTable.NewRow();
dr["ID"] = "0";
dr["Name"] = "SELECT NAME";
dataTable.Rows.Add(dr);
DataRow dr1 = dataTable.NewRow();
dr1["ID"] = "1";
dr1["Name"] = "Name1";
dataTable.Rows.Add(dr1);
DataRow dr2 = dataTable.NewRow();
dr2["ID"] = "2";
dr2["Name"] = "Name2";
dataTable.Rows.Add(dr2);
DataRow dr3 = dataTable.NewRow();
dr3["ID"] = "3";
dr3["Name"] = "Name3";
dataTable.Rows.Add(dr3);
return dataTable;
}
protected void btnSubmit_click(object sender, EventArgs e)
{
RadComboBox1.Items[0].Selected = true;
}
}
Thanks,
9 Answers, 1 is accepted
Based on your code and logic, I presume that the selecteditem text is not showing even if the item is selected. Have you tried setting the Text explicitly to overcome this?
Give a try with the following code and let me know if you need further assistance.
C#:
protected void btnSubmit_click(object sender, EventArgs e) { RadComboBox2.Items[0].Selected = true; RadComboBox2.Text = RadComboBox2.Items[0].Text; }Thanks,
Princy.
i have a Telerik:RadCombobox but i am having some difficulty trying to do something which i am to believe is rather simple, let me paste some code for you
<telerik:RadComboBox ID="CPPActionRadCombo" runat="server" EmptyMessage="Select Action" Skin="Outlook"> <Items> <telerik:RadComboBoxItem Text="Append" Value="1" runat="server" /> <telerik:RadComboBoxItem Text="Override" Value="2" runat="server" /> </Items> </telerik:RadComboBox>ok so not that its not working, it does, the thing is when i look at this combobox, i have 3 values
Select Action
Append
Override
So when the page loads i want the user to see "Select Action" as a default
so when he clicks on the combobox he can choose Append or override, i do not want the user to be able to select the option "Select Action" or see it as an item, i just want that as an indicator in the combobox to say that here they must select an action, once they have selected an action i don't want them to be able to select "Select Action"
so put easy for you
there should only be 2 values that can be selected, but when the page loads i want the combobox to show me "Select Action" but in reality it must not be select-able
Please Help, Please please
The default behavior of RadComboBox is that it will not allow to select the EmptyMeaasge. In your scenario you have set 'Select Action' as the EmptyMeassage so it will not be available in the dropdownlist and the 'Select Action' will show only at first time.
Please elaborate your requirement if it doesn't help.
Thanks,
Shinu.
<telerik:RadComboBox ID="ActionRadCombo" TabIndex="20" runat="server" Text="Select Action" EmptyMessage="Select Action" Skin="Outlook">
<Items>
<telerik:RadComboBoxItem Visible="False" Text="" Value="-1" IsSelected="true" runat="server" />
<telerik:RadComboBoxItem Text="Append" Value="1" runat="server" />
<telerik:RadComboBoxItem Text="Override" Value="2" runat="server" />
</Items>
</telerik:RadComboBox>
Hi. New to Telerik controls, fyi.
I'm unable to "title" the RadComboBox by using the aspnet method described here: https://docs.telerik.com/devtools/aspnet-ajax/controls/combobox/radcombobox-items/default-item.
Here's my setup:
<div class="a-Container" runat="server" id="aContainer"> <div class="headerArea"> <img class="btnNavImg" id="cbsLogo" src="Images/cbs-logo-png-transparent.png" /> <telerik:RadComboBox RenderMode="Lightweight" ID="RadListBox1" runat="server" CheckBoxes="true" Skin="BlackMetroTouch"> <Items> <telerik:RadComboBoxItem Text="Payment" /> <telerik:RadComboBoxItem Text="Entity" /> <telerik:RadComboBoxItem Text="Amount" /> <telerik:RadComboBoxItem Text="State" /> <telerik:RadComboBoxItem Text="Reviewer" /> </Items> </telerik:RadComboBox> </div> <telerik:RadGrid ID="RadGrid1" runat="server" RenderMode="Lightweight" DataSourceID="gridSource" AllowSorting="true" Skin="Bootstrap"> <ClientSettings AllowColumnsReorder="False" ReorderColumnsOnClient="True" EnableRowHoverStyle="true"> <Selecting AllowRowSelect="True" /> <Scrolling AllowScroll="True" UseStaticHeaders="True" /> <Resizing AllowColumnResize="true" AllowResizeToFit="true" /> <%--ResizeGridOnColumnResize="true" --%> </ClientSettings> <MasterTableView CssClass="MasterClass" DataSourceID="gridSource" AutoGenerateColumns="false"> <Columns> <telerik:GridDateTimeColumn DataField="ProductID" ReadOnly="True" HeaderText="Payment Due Date" SortExpression="ProductID" UniqueName="ProductID" DataType="System.DateTime" DataFormatString="{0:MM/dd/yyyy}" ItemStyle-HorizontalAlign="Right" PickerType="DatePicker" EnableTimeIndependentFiltering="true"> </telerik:GridDateTimeColumn> <telerik:GridBoundColumn DataField="ProductName" ReadOnly="True" HeaderText="Tax Project Entity" SortExpression="ProductName" UniqueName="ProductName"> </telerik:GridBoundColumn> <telerik:GridBoundColumn DataField="UnitPrice" ReadOnly="True" HeaderText="Amount" SortExpression="UnitPrice" UniqueName="UnitPrice" DataType="System.Decimal" DataFormatString="{0:C2}" ItemStyle-HorizontalAlign="Right"> </telerik:GridBoundColumn> <telerik:GridBoundColumn DataField="Region" ReadOnly="True" HeaderText="State" SortExpression="Region" UniqueName="Region"></telerik:GridBoundColumn> <%-- If non-admin this column disappears --%> <telerik:GridBoundColumn DataField="ContactName" ReadOnly="True" HeaderText="Reviewer 1" SortExpression="ContactName" UniqueName="ContactName"></telerik:GridBoundColumn> <telerik:GridBoundColumn DataField="doc" ReadOnly="True" HeaderText="Associated Document" SortExpression="doc" UniqueName="doc"></telerik:GridBoundColumn> <%-- <telerik:GridButtonColumn HeaderText="asdf" Text="Edit Needed" CommandName="" CommandArgument="GoToLinkArg2"></telerik:GridButtonColumn> <telerik:GridButtonColumn HeaderText="asdf" Text="Sign with DocuSign" CommandName="" CommandArgument="GoToLinkArg"></telerik:GridButtonColumn>--%> <%-- If non-admin this column appears and the next GridTemplateColumn disappears <telerik:GridButtonColumn HeaderText="Desired Action" Text="Sign with DocuSign" CommandName="" CommandArgument="GoToLinkArg"> </telerik:GridButtonColumn> --%> <telerik:GridTemplateColumn HeaderText="Desired Action"> <ItemTemplate> <asp:LinkButton CssClass="EditNeeded" CommandName="Edit" runat="server" Text="Edit Needed" href="http://aintwet.nyc/" /> <asp:LinkButton CssClass="SignDocusign" CommandName="Delete" runat="server" Text="Sign with DocuSign" href="https://www.lingscars.com/" /> </ItemTemplate> </telerik:GridTemplateColumn> </Columns> </MasterTableView> </telerik:RadGrid> </div>I had the <DefaultItem> just above <Items> in the RadComboBox, like so:
<telerik:RadComboBox RenderMode="Lightweight" ID="RadListBox1" runat="server" CheckBoxes="true" Skin="BlackMetroTouch"> <DefaultItem Text="Please select country" Value="-1"/> <Items> <telerik:RadComboBoxItem Text="Payment" /> <telerik:RadComboBoxItem Text="Entity" /> <telerik:RadComboBoxItem Text="Amount" /> <telerik:RadComboBoxItem Text="State" /> <telerik:RadComboBoxItem Text="Reviewer" /> </Items></telerik:RadComboBox>
And now is when I realize I'm a dummy. There is no data at this point. So, my question is changing to: Can I put a "placeholder" as a default name for the box?
Hello Bonnie,
The "placeholder" for the RadComboBox is set via the EmptyMessage property
<telerik:RadComboBox ID="RadComboBox1" EmptyMessage="Placeholder text here..." runat="server" RenderMode="Lightweight">
<Items>
<telerik:RadComboBoxItem Text="Item 1" />
<telerik:RadComboBoxItem Text="Item 2" />
<telerik:RadComboBoxItem Text="Item 3" />
<telerik:RadComboBoxItem Text="Item 4" />
</Items>
</telerik:RadComboBox>Regards,
Peter Milchev
Progress Telerik
