DetailsView控件ObjectDataSource参数化选择Issue

发布于 2024-09-30 10:46:44 字数 2047 浏览 0 评论 0原文

我正在使用 GridView 和详细信息视图,我的数据源是返回数据集的自定义 ObjectDataSource。

这不是 SQL 服务器,我正在使用 LDAP 查询从 Active Directory 获取用户。

我在 ASPX 页面中有两个自定义数据源,其中一个绑定到 GridView,另一个绑定到 DetailsView。它们都有有效的 SelectMethods 和参数。

GridView 工作得很好。当我针对 Active Directory 运行查询时,我会在 GridView 中获取带有自动生成的选择链接的人员列表。我可以单击此链接,它会通过 DataKeyNames 将我想要的任何值传递给 SelectedIndexChanged 事件。

我在此事件中所做的是设置DetailsView 控件的ObjectDataSource 参数。它确实调用自定义类并返回包含一个用户的数据集。

这里有趣的是,当我在 ASPX 页面中设置此 ObjectDataSource 时,我给它一个默认参数值。加载页面时,DetailsView 控件将显示通过默认参数返回的值。

所以...我知道这在某种程度上是有效的。

但是,当我在 GridView 的 SelectedIndexChanged 事件中设置参数时,自定义类中的 select 方法将运行并返回正确的 DataSet,但 DetailsView 控件使用新信息进行更新。

这是DetailsView 的ObjectDataSource 的ASPX 代码:

<asp:ObjectDataSource ID="_prvODSDetailsView" 
                  SelectMethod="_pubGetSingleUserDataSetByKerberosID"
                  TypeName="NotImportant"
                  runat="server">
   <SelectParameters>
  <asp:Parameter Direction="Input" Name="param_KerberosID" Type="String" DefaultValue="somedefaultvalue" />
   </SelectParameters>
</asp:ObjectDataSource>  

这是我的DetailsView 代码:

<asp:DetailsView ID="_prvDetailsViewShown" 
          CssClass="detailgrid"
          GridLines="None"
          DefaultMode="Edit"
          EmptyDataText="<No Details Available>"
          AutoGenerateRows="true"
          DataKeyNames="KerberosID"
          DataSourceID="_prvODSDetailsView"
          Width="100%"
          runat="server">
</asp:DetailsView>

只是重申一下。这适用于使用参数默认值的第一页加载。

void _prvGridView_SelectedIndexChanged( object sender, EventArgs e )
{
    DataKey k = _prvGridView.SelectedDataKey;
    string kerberosID = k.Value.ToString();
    Parameter parameter = new Parameter( "param_KerberosID", TypeCode.String, kerberosID );
    _prvODSDetailsView.SelectParameters[ 0 ] = parameter;
}

我期望发生的是绑定发生并且控件自动更新。事实上,我很确定 DetailsView 绑定确实发生了,但控件永远不会更新。

我缺少什么?

I'm using a GridView and Details View and my datasource is a custom ObjectDataSource that returns a DataSet.

This isn't a SQL server, I'm using an LDAP query to get users from Active Directory.

I have two custom datasources in the ASPX page with one bound to the GridView and one to the DetailsView. They both have SelectMethods and Parameters that work.

The GridView works perfectly. When I run the query against the Active Directory, I get my list of people in the GridView with an autogenerated select link. I can click on this link and it passes whichever value I want via the DataKeyNames to the SelectedIndexChanged event.

What I'm doing in this event is setting the parameter for the ObjectDataSource for the DetailsView control. It does call into the custom class and return back a DataSet that contains ONE USER.

What's interesting here is that when I setup this ObjectDataSource in the ASPX page, I give it a Default parameter value. When the page loads, the DetailsView control shows up with the values returned via the default parameter.

So...I know this works to some degree.

However, when I set the parameter in the SelectedIndexChanged event for the GridView, the select method in the custom class runs and returns the proper DataSet, but the DetailsView control is not updated with the new information.

Here's the ASPX code for ObjectDataSource for the DetailsView:

<asp:ObjectDataSource ID="_prvODSDetailsView" 
                  SelectMethod="_pubGetSingleUserDataSetByKerberosID"
                  TypeName="NotImportant"
                  runat="server">
   <SelectParameters>
  <asp:Parameter Direction="Input" Name="param_KerberosID" Type="String" DefaultValue="somedefaultvalue" />
   </SelectParameters>
</asp:ObjectDataSource>  

Here's my DetailsView code:

<asp:DetailsView ID="_prvDetailsViewShown" 
          CssClass="detailgrid"
          GridLines="None"
          DefaultMode="Edit"
          EmptyDataText="<No Details Available>"
          AutoGenerateRows="true"
          DataKeyNames="KerberosID"
          DataSourceID="_prvODSDetailsView"
          Width="100%"
          runat="server">
</asp:DetailsView>

Just to reiterate. This works on the first page load using the default value from the parameter.

void _prvGridView_SelectedIndexChanged( object sender, EventArgs e )
{
    DataKey k = _prvGridView.SelectedDataKey;
    string kerberosID = k.Value.ToString();
    Parameter parameter = new Parameter( "param_KerberosID", TypeCode.String, kerberosID );
    _prvODSDetailsView.SelectParameters[ 0 ] = parameter;
}

What I'm expecting to happen is the binding occurs and the control gets automatically updated. In fact, I'm pretty sure the DetailsView binding does occur, but the control never gets updated.

What am I missing?

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

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

发布评论

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

评论(1

迟到的我 2024-10-07 10:46:44

嗯,我找到了答案。我的 GridView 位于 UpdatePanel (ASP .NET AJAX) 中,而 DetailsView 则不然。显然,你不能拥有它。

当删除所有 AJAX 组件后,它就可以工作了。

当我将 DetailsView 放在与 GridView 相同的 UpdatePanel 中时,它也起作用了。

Well, I found the answer. My GridView is in an UpdatePanel (ASP .NET AJAX) and the DetailsView as not. Apparently, you can't have that.

When removed all of the AJAX components, it worked.

When I put the DetailsView in the SAME UpdatePanel as the GridView, it also worked.

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