将 RadComboBox 添加到 RadGrid 编辑

发布于 2024-08-02 00:48:49 字数 495 浏览 9 评论 0原文

我已经添加了 RadControl、RadGrid,我需要在编辑模式下添加 radComboBox。

当用户单击 radComboBox 时,我需要获取 radComboBox 的“文本”和“值”,以便在用户更新值时保存到表中。

<telerik:RadComboBox ID="RadComboBox1" Runat="server" 
             DataSourceID="SqlDataSource1" DataTextField="docCategoryName" 
             DataValueField="docCategoryID" Height="200px" Skin="Vista">

当用户从 radComboBox 中选择时,我需要获取 DataTextField 和 DataTextField 的值。 DataValueField 转换为 HiddenField。

I have added a RadControl, RadGrid and I need to add a radComboBox in the edit mode.

When user clicks on the radComboBox, I need to get both "text" and "value" of the radComboBox to save to table when user updates values.

<telerik:RadComboBox ID="RadComboBox1" Runat="server" 
             DataSourceID="SqlDataSource1" DataTextField="docCategoryName" 
             DataValueField="docCategoryID" Height="200px" Skin="Vista">

When user selects from the radComboBox, I need to get the value of DataTextField & DataValueField into a HiddenField.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

皓月长歌 2024-08-09 00:48:49

Program.X 描述的方法非常好。 当然,如果您在 RadGrid 中的 GridTemplateColumn 内使用 RadCombobox,则此方法有效。

RadGrid 还提供了内置的 GridDropDownColumn,可以在编辑期间自动呈现 RadCombobox。 如果您选择使用内置列类型,则需要以编程方式为呈现的 RadGrid 设置客户端事件处理程序,如下所示:

protected void RadGrid1_ItemCreated(object sender, Telerik.Web.UI.GridItemEventArgs e)
{
    //Find GridEditableItems when in Edit mode
    if (e.Item is GridEditableItem && e.Item.IsInEditMode)
    {
        //Get reference to item (i.e. Row)
        var item = e.Item as GridEditableItem;

        //Get reference to auto-generated RadCombobox in
        //specific column (in this case, a column called Title)
        var rcb = item["Title"].Controls[0] as RadComboBox;
        if (rcb == null)
            return;

        //Customize the RadCombobox properities
        rcb.OnClientSelectedIndexChanged = "onselectedindexchanged";
    }
}

其中“onselectedindexchanged”是页面上的客户端 JavaScript 函数的名称,旨在处理 RadCombobox 事件。

这些方法中的任何一种都应该能让您实现您的目标。

The approach described by Program.X is very good. This, of course, works if you're using a RadCombobox inside of a GridTemplateColumn in RadGrid.

RadGrid also provides a built-in GridDropDownColumn that can automatically render a RadCombobox during edits. If you choose to use the built-in column type, you need to programmatically set the client-side event handlers for the rendered RadGrid, like this:

protected void RadGrid1_ItemCreated(object sender, Telerik.Web.UI.GridItemEventArgs e)
{
    //Find GridEditableItems when in Edit mode
    if (e.Item is GridEditableItem && e.Item.IsInEditMode)
    {
        //Get reference to item (i.e. Row)
        var item = e.Item as GridEditableItem;

        //Get reference to auto-generated RadCombobox in
        //specific column (in this case, a column called Title)
        var rcb = item["Title"].Controls[0] as RadComboBox;
        if (rcb == null)
            return;

        //Customize the RadCombobox properities
        rcb.OnClientSelectedIndexChanged = "onselectedindexchanged";
    }
}

Where "onselectedindexchanged" is the name of a client-side JavaScript function on your page designed to handle the RadCombobox event.

Either of these approaches should enable you to achieve your goal.

客…行舟 2024-08-09 00:48:49

Telerik 是帮助您解决此问题的最佳人选,但是来自他们的网站(并且根据记忆):

http://www.telerik.com/help/aspnet-ajax/combo_clientsideonclientselectedindexchanged.html

如果您有 radCombo:

<telerik:RadComboBox
 ID="RadComboBox1"
 runat="server"
 OnClientSelectedIndexChanged="OnClientSelectedIndexChanged">
</telerik:RadComboBox> 

使用您的 JS 事件:

<script language="javascript" type="text/javascript">
function OnClientSelectedIndexChanged(sender, eventArgs)
{
 var item = eventArgs.get_item();

// get the text and value elements
var text=item.get_text();
var val=item.get_value();

$('#hiddenField').val(val);
}
</script>

其中hiddenField 是隐藏字段的 ID。

Telerik are the best people to help you with this, but from their site (and from memory):

http://www.telerik.com/help/aspnet-ajax/combo_clientsideonclientselectedindexchanged.html

If you have your radCombo:

<telerik:RadComboBox
 ID="RadComboBox1"
 runat="server"
 OnClientSelectedIndexChanged="OnClientSelectedIndexChanged">
</telerik:RadComboBox> 

With your JS event:

<script language="javascript" type="text/javascript">
function OnClientSelectedIndexChanged(sender, eventArgs)
{
 var item = eventArgs.get_item();

// get the text and value elements
var text=item.get_text();
var val=item.get_value();

$('#hiddenField').val(val);
}
</script>

Where hiddenField is the ID of the hidden field.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文