- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我有一个网页,在页面上的 radgrid 控件中有一个 Telerik RadComboBox,我有一个 SqlserverCe 数据库。我的问题是如何编写代码以在 asp.net 的页面加载事件中绑定(bind) RadCombobox 请帮助我.....
最佳答案
项目绑定(bind)到 RadComboBox 的方式基本上与绑定(bind)到 ASP.NET DropDownList 的方式相同。
您可以将 RadComboBox 绑定(bind)到 ASP.NET 2.0 datasources , ADO.NET DataSet/DataTable/DataView , 至 Arrays and ArrayLists ,或对象的 IEnumerable。当然,您也可以自己一项一项地添加。对于 RadComboBox,您将使用 RadComboBoxItems 而不是 ListItems。
无论以何种方式,您都必须告诉组合框每个项目的文本和值是什么。
Working with Items in Server Side Code :
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
RadComboBoxItem item1 = new RadComboBoxItem();
item1.Text = "Item1";
item1.Value = "1";
RadComboBox1.Items.Add(item1);
RadComboBoxItem item2 = new RadComboBoxItem();
item2.Text = "Item2";
item2.Value = "2";
RadComboBox1.Items.Add(item2);
RadComboBoxItem item3 = new RadComboBoxItem();
item3.Text = "Item3";
item3.Value = "3";
RadComboBox1.Items.Add(item3);
}
}
Binding to DataTable, DataSet, or DataView :
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
SqlConnection con = new SqlConnection("Data Source=LOCAL;Initial Catalog=Combo;Integrated Security=True");
SqlDataAdapter adapter = new SqlDataAdapter("SELECT [Text], [Value] FROM [Links]", con);
DataTable links = new DataTable();
adapter.Fill(links);
combo.DataTextField = "Text";
combo.DataValueField = "Value";
combo.DataSource = links;
combo.DataBind();
}
}
编辑: RadComboBox in a Grid :
在 RadGrid 中,通过设置 EnableLoadOnDemand="True" 并处理 OnItemsRequested 事件,使用按需加载可能是最简单的。
protected void RadComboBox1_ItemsRequested(object sender, RadComboBoxItemsRequestedEventArgs e)
{
string sql = "SELECT [SupplierID], [CompanyName], [ContactName], [City] FROM [Suppliers] WHERE CompanyName LIKE @CompanyName + '%'";
SqlDataAdapter adapter = new SqlDataAdapter(sql,
ConfigurationManager.ConnectionStrings["NorthwindConnectionString"].ConnectionString);
adapter.SelectCommand.Parameters.AddWithValue("@CompanyName", e.Text);
DataTable dt = new DataTable();
adapter.Fill(dt);
RadComboBox comboBox = (RadComboBox)sender;
// Clear the default Item that has been re-created from ViewState at this point.
comboBox.Items.Clear();
foreach (DataRow row in dt.Rows)
{
RadComboBoxItem item = new RadComboBoxItem();
item.Text = row["CompanyName"].ToString();
item.Value = row["SupplierID"].ToString();
item.Attributes.Add("ContactName", row["ContactName"].ToString());
comboBox.Items.Add(item);
item.DataBind();
}
}
您还可以在网格的 OnItemDataBoundHandler 事件中手动绑定(bind)组合框:
protected void OnItemDataBoundHandler(object sender, GridItemEventArgs e)
{
if (e.Item.IsInEditMode)
{
GridEditableItem item = (GridEditableItem)e.Item;
if (!(e.Item is IGridInsertItem))
{
RadComboBox combo = (RadComboBox)item.FindControl("RadComboBox1");
// create and add items here
RadComboBoxItem item = new RadComboBoxItem("text","value");
combo.Items.Add(item);
}
}
}
关于c# - 如何在运行时在 asp.net 中绑定(bind) radcombobox,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6261075/
当我点击我的按钮时,我得到了 SelectedValue = ""。 我的aspx: 我的.cs: private void BindContactLists(int year,
Dim sb As StringBuilder = New StringBuilder() sb.Append("") sb.Append(" function
我试图在文本左侧显示一个箭头,但我不知道如何设置它的格式才能使其正常工作。 我对 rad box 的标记如下:
当您单击典型的 ComboBox 时,它会展开。当您再次单击它时,它会折叠。 当您单击 RadComboBox 时,它会展开。当您再次单击它时,没有任何反应。也就是说,除非您单击箭头或实际进行选择。
问: 我使用 RadComboBox 来过滤我的大列表,但我面临两个问题: 1-下拉展开需要很长时间!! 2- 仅在 firefox 中进行过滤,在 internet 中不进行过滤 探险家!! 我的.
当我使用 RadComboBox 时遇到以下问题: ddl_contactList.Items.Clear(); ddl_contactList.DataSource = Contac
我正在尝试将一个项目添加到下拉列表的顶部。我正在使用 ItemTemplates,所以我正在进行数据绑定(bind)并尝试在顶部添加一个内容 [ ] All Profiles 我能够添加它,但它覆盖了
所以我有一个 RadCombBox,它经过大量编辑以包含一个选项列表,其中 1 个选项可以是输入字段。您可以选择不同类型的输入字段,但我对整数输入字段有疑问。还有一个带有文本输入字段,显示没有问题。
我有一个 Telerik 的 radcombobox像下面这样: 当我在文本框中键入不在其项目列表中的内容然后转到其他控件时,它会清除其中的文本,这是我不想要的。 我已经检查了所有属性,但在失去焦点
我有值 0、1、2 的组合框。当用户展开组合框以选择值时,我想将值的文本显示为 0 - 差,1 - 平均,2 - 好。 但是当用户选择值时,我只想显示该值。 我该怎么做?这是我的代码
我对使用 ASP 网络表单和 Telerik 比较陌生,但我正在寻找一种方法,可以让我在 RadComboBox 中输入特殊字符(é、ù、à、...) . 假设我的 ObjectDataSource
Silverlight 中的 RadComboBox 控件具有键盘支持,在本页中列出:Keyboard Support 除了键盘支持,我需要 RadComboBox 功能。我在网上找不到任何东西可以帮
我想列出 radcombobox 中的所有项目(值是从数据集中绑定(bind)的)但不应允许用户从 radcombobox 中选择任何值。 用户应该能够看到所有项目,但应该禁用选择项目。 如果有任何帮
我的以下代码是否有任何内容会阻止触发客户端事件“OnClientItemsRequested”?我在页面上有几个 RadComboBox 元素,它们有时会进入一种状态,即它们不加载任何内容并且不触发“
大家下午好(池塘那边的人早上好)。 我收到一个非常奇怪的 Telerik 错误,我想知道你们中是否有任何有 Telerik 经验的人以前遇到过这个错误。 我正在使用 RadComboBox,在尝试构建
我有 telerik radcombobox,它有一些项目从数据库绑定(bind)到它。第一个项目总是“新帐户”,其余的将添加到它旁边。我的代码是aspx aspx.cs 页面加载代码是 R
我的页面上有一个多选的 telerik RadComboBox 组件。我正在使用“OnClientDropDownClosed”客户端事件。我确实手动回发,而不是自动回发。我想要的是,当下拉菜单关闭时
我正在使用 radcombobox 来显示数据,现在我没有为 radcombox 使用任何 css 样式,但它仍然具有灰色背景。 我想删除那个颜色。下面是我的 rad 组合框代码:
我是 Telerik 组件的新手,我遇到了一个奇怪的问题。 我通过 JS 调用基于另一个组合框选择的 requestItems 来填充 RadComboBox。 数据填充正确,但在视觉上只有当我第二次
当我将 Office2007-Skin 用于 Telerik-Controls 时,RadComboBox 在正常模式下将具有蓝色: 我正在寻找一种方法,使 RadComboBox 看起来像: 我只想
我是一名优秀的程序员,十分优秀!