我有一个基本的 1 表格网格。我有一个名为分支类型的字段。分店类型只能是 Corporate 或 Franchise。当我单击 ASPxgridview 行上的编辑按钮时,我想在编辑表单上显示和隐藏字段,具体取决于它是什么分支类型。因此,如果是公司,我想显示经理字段并隐藏所有者字段。当分支类型为 Franchise 时,我希望在编辑表单上显示 Owner 字段并隐藏 Manager 字段。所有细节都可以显示在网格视图上,但在编辑表单上我想强制用户只填写适用的字段。
如果你看下面:
这基本上是我在加载编辑表单时想要实现的目标:
protected void ASPxGridViewStores_CellEditorInitialize(object sender, ASPxGridViewEditorEventArgs e)
{
if (!ASPxGridViewStores.IsEditing || e.Column.FieldName != "StoreOwnershipID") return;
if(e.KeyValue == DBNull.Value || e.KeyValue == null) return;
object val = ASPxGridViewStores.GetRowValuesByKeyValue(e.KeyValue, "S_ID");
if(val == DBNull.Value) return;
int StoreOwnershipID = (Int32)val;
if (StoreOwnershipID == 4)
{ ASPxComboBox ManagerID = (ASPxComboBox)ASPxGridViewStores.FindEditFormTemplateControl("ManagerID");
ManagerID.Enabled = true;
ASPxComboBox ContactID = (ASPxComboBox)ASPxGridViewStores.FindEditFormTemplateControl("ContactID");
ManagerID.Enabled = true;
}
else
{ ASPxComboBox ManagerID = (ASPxComboBox)ASPxGridViewStores.FindEditFormTemplateControl("ManagerID");
ManagerID.Enabled = false;
ASPxComboBox ContactID = (ASPxComboBox)ASPxGridViewStores.FindEditFormTemplateControl("ContactID");
ManagerID.Enabled = false;
}
}
然后根据在“StoreOwnershipID”字段中选择公司或特许经营权,我将使用客户端脚本来启用或禁用其他字段。
我也做了一些研究,我想出了以下代码:
SelectedIndexChanged="function(s, e) {
var value = s.GetValue();
if(value == 4)
GridViewStores.GetEditor("OwnerName").SetVisible(true);
else
GridViewStores.GetEditor("OwnerName").SetVisible(false);
}"
但是当它被调用时,我得到以下错误:
Microsoft JScript 运行时错误:“GridViewStores”未定义
我在 web.config 中添加了 HTTPhandler:
<httpModules>
<add type="DevExpress.Web.ASPxClasses.ASPxHttpHandlerModule, DevExpress.Web.v10.2, Version=10.2.4.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" name="ASPxHttpHandlerModule" />
</httpModules>
和
<system.webServer>
<modules>
<add type="DevExpress.Web.ASPxClasses.ASPxHttpHandlerModule, DevExpress.Web.v10.2, Version=10.2.4.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" name="ASPxHttpHandlerModule" />
</modules>
正如你在下面看到的,我已经插入了 ClientInstanceName,
我已将 ClientIDMode 从 AutoID 更改为 Inherit 到 Static 到 Predictable 并且每个场景都不起作用并且仍然呈现:Microsoft JScript 运行时错误:'ASPxGridview' 未定义。
在我的 gridview 标签下方
<dx:ASPxGridView ID="ASPxGridView" runat="server" AutoGenerateColumns="False"
ClientIDMode="Predictable" DataSourceID="SqlDataSource1" KeyFieldName="S_ID"
ClientInstanceName="ASPxGridView">
我现在什至尝试创建一个仅包含 sqldatasource 和 gridview 的新页面,其中 storetype 字段为 acombobox,并包括我之前帖子中提到的 javascript.. 完全没有运气。我已经给了你我的 web.config 设置,我在其中声明了 httphandler,那么你还有什么建议我可以让它工作的呢?
这是我的网络配置:
部分启用 ASP.NET 用来识别传入用户的安全身份验证模式的配置。--> 部分可以配置如果/当在执行请求期间发生未处理的错误时要做什么。具体来说,它使开发人员能够配置要显示的 html 错误页面来代替错误堆栈跟踪。
<customErrors mode="RemoteOnly" defaultRedirect="GenericErrorPage.htm">
<error statusCode="403" redirect="NoAccess.htm" />
<error statusCode="404" redirect="FileNotFound.htm" />
</customErrors>
-->
<httpModules>
<add type="DevExpress.Web.ASPxClasses.ASPxHttpHandlerModule, DevExpress.Web.v10.2, Version=10.2.4.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" name="ASPxHttpHandlerModule" />
</httpModules>
<httpHandlers>
<add type="DevExpress.Web.ASPxClasses.ASPxHttpHandlerModule, DevExpress.Web.v10.2, Version=10.2.4.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" verb="GET" path="DX.ashx" validate="false" />
</httpHandlers>
<pages controlRenderingCompatibilityVersion="3.5" clientIDMode="AutoID" />
抱歉这个问题。顺便说一下,这是使用 DevExpress Gridview。devexpress 的人无法帮助我并花 1 天时间来回答一个问题,所以它已经持续了将近一个星期......
谢谢维尔纳