自定义数据源扩展器

发布于 2024-09-05 18:00:40 字数 1028 浏览 1 评论 0原文

我梦想创建一个像这样工作的控件:

 <asp:SqlDataSource
      id="dsFoo"
      runat="server"
      ConnectionString="<%$ ConnectionStrings:conn %>"
      SelectCommandType="StoredProcedure"
      SelectCommand="cmd_foo">
 </asp:SqlDataSource>

<Custom:DataViewSource
     id="dvFoo"
     runat="server"
     rowfilter="colid &gt; 10"
     datasourceid="dsFoo">
</Custom:DataViewSource>

我可以通过执行 cmd_foo 在后面的代码中完成同样的事情,将结果加载到 DataTable 中,然后加载它们到带有 RowFilterDataView 中。目标是为一个 DataSource 提供多个 DataView,并使用我希望应用于 DataSource 的选择部分的任何特殊过滤器。我可以想象将其扩展为更强大。

我尝试在 this这个但我对一些内容有点困惑点。

目前,我的主要问题是不确定在哪里获取 DataSource 的输出数据,以便我可以将其粘贴到 DataTable 中。

I dream of creating a control which works something like this:

 <asp:SqlDataSource
      id="dsFoo"
      runat="server"
      ConnectionString="<%$ ConnectionStrings:conn %>"
      SelectCommandType="StoredProcedure"
      SelectCommand="cmd_foo">
 </asp:SqlDataSource>

<Custom:DataViewSource
     id="dvFoo"
     runat="server"
     rowfilter="colid > 10"
     datasourceid="dsFoo">
</Custom:DataViewSource>

I can accomplish the same thing in the code behind by executing cmd_foo, loading the results into a DataTable, then loading them into a DataView with a RowFilter. The goal would be to have multiple DataViews for one DataSource with whatever special filters I wish to apply to the select portion of the DataSource. I could imagine extending this to be more powerful.

I tried peaking at this and this but am a bit confused on a few points.

Currently, my main issue is being unsure where to grab the output data of the DataSource so I can stick it into a DataTable.

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

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

发布评论

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

评论(1

蓝眼泪 2024-09-12 18:00:40

我陷入困境的代码:

DataView dv = dsFoo.Select(DataSourceSelectArguments.Empty) as DataView;
DataTable dt = dv.ToTable()

第二行可能是不必要的,因为最初的目标是将 DataSource 转换为 DataView

当然,查找这些东西告诉我 SqlDataSource 已经有 FilterExpression...

The code I was stuck at:

DataView dv = dsFoo.Select(DataSourceSelectArguments.Empty) as DataView;
DataTable dt = dv.ToTable()

The second line is likely unnecessary since the original goal was to turn a DataSource into a DataView.

Of course, looking up this stuff tells me that SqlDataSource already has FilterExpression...

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