【问题标题】:how do I access the textbox in a column when I click "Add new record" in the telerik radgrid当我单击 Telerik radgrid 中的“添加新记录”时,如何访问列中的文本框
【发布时间】:2010-06-16 19:15:26
【问题描述】:

我有一个单击“添加新记录”按钮的网格,显示带有角色的文本框:[TextBox] 以及它下方的复选框和取消按钮。该网格只有一个名为 RoleName 的列,其标题为 Role,如下所示。


(来源:rjmueller.net

当我单击复选框按钮时,我正在触发使用具有三个参数(applicationId、applicationName、rolename)的 objectdatasource 的 InsertCommand。 roleName 需要是文本框的值。

我的网格叫做 gvRoles。

我的对象数据源称为 dsSecurity。

我可以使用几行代码来获取这个值吗?

        protected void gvRoles_InsertCommand(object source, GridCommandEventArgs e)   
    {   
        //I need code here to retrieve the value of the textbox   

        dsSecurity.InsertMethod = "InsertRole";   

        String applicationId = cmbApplications.SelectedValue;   
        String applicationName = cmbApplications.SelectedItem.Text;   
        String roleName = "I need to set the role name from the textbox";   
        dsSecurity.InsertParameters["applicationId"].DefaultValue = applicationId;   
        dsSecurity.InsertParameters["applicationName"].DefaultValue = applicationName;   
        dsSecurity.InsertParameters["roleName"].DefaultValue = roleName;   

        gvRoles.DataBind();   
    }  

【问题讨论】:

    标签: c# .net asp.net telerik


    【解决方案1】:

    如果您有自动生成的 Telerik 网格编辑表单,我会使用此代码来获得您想要的内容:

    String roleName = ((e.Item as GridEditableItem)["Role"].Controls[0] as TextBox).Text;

    如果您使用自定义编辑表单,请直接调用 e.Item.FindControl(id) 获取对文本框的引用。

    迪克

    【讨论】:

    • 像往常一样,Stackoverflow 再次为我服务。很好的回答,迪克,感谢您的帮助,它完全符合我的要求。
    猜你喜欢
    • 1970-01-01
    • 2014-05-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多