【问题标题】:Customize and accessing controls onItemCommand自定义和访问控件 onItemCommand
【发布时间】:2012-09-20 09:58:57
【问题描述】:

这是我的代码

<EditFormSettings PopUpSettings-Width="500" EditFormType="Template">
 <FormTemplate>
 <asp:DropDownList ID="Status" DataSourceID="TerminalStatusDTS" DataValueField="STATUS_ID" DataTextField="STATUS_NAME"  runat="server"  Width="175px"  ></asp:DropDownList>
 </FormTemplate>

我的问题是如何使Statuse.commandName=RadGrid.InitInsertCommandName onItemCommand 事件中不可见?

【问题讨论】:

    标签: telerik radgrid


    【解决方案1】:

    RadGrid 的每一行的EditForm 都不同。首先,您必须获取正在编辑的行的行索引并获取对 Edit 表单的引用。然后你可以在编辑表单中找到Control。示例代码如下:

    if (e.CommandName == RadGrid.InitInsertCommandName)
    {
        RadGrid radgrid = (RadGrid)sender;
        int rowindex = e.Item.RowIndex;
        GridEditFormItem item = radgrid.MasterTableView.GetItems(GridItemType.EditFormItem)[rowindex] as GridEditFormItem;
        DropDownList statusDropDownList = (DropDownList)item.FindControl("Status");
        statusDropDownList.Visible = false;
    }
    

    但是,这可能不是您所需要的。我的意思是当页面在 ItemCommand 上进行回发时,状态下拉列表将可见,我认为您只需要在单击插入命令时隐藏控件(更新和插入的不同行为)。

    因此您可以访问 DropDownList 并将其隐藏在 ItemCreated 事件或 ItemDataBound 事件中。

    例如:

    void rad_ItemDataBound(object sender, GridItemEventArgs e)
    {
        if (e.Item is GridEditFormInsertItem)
        {
            DropDownList statusDropDownList = (DropDownList)e.Item.FindControl("Status");
            statusDropDownList.Visible = false;
        }
    }
    

    【讨论】:

      猜你喜欢
      • 2011-01-09
      • 2014-12-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-03-22
      • 1970-01-01
      相关资源
      最近更新 更多