- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我有一个包含许多列的可编辑 GridView 。其中两个是 100mPlot 和 SubPlot。 SubPlot 不是唯一的(1A、1B、1C 和 1D),但 100mPlot + SubPlot 构成了一组唯一的值。
当用户点击“编辑”时,他们将在“子图”列中看到一个下拉列表。此列表需要基于 100mPlot 的值。因此,为了显示 SubPlot 的正确值,我需要将 100mPlot 列的值作为参数传递给将绑定(bind)到 SubPlot 下拉列表的 sqldatasource。我该怎么做?
<asp:BoundField DataField="100mPlot" HeaderText="100m plot"
SortExpression="100mPlot" ReadOnly="True" />
<asp:TemplateField HeaderText="SubPlot" SortExpression="SubPlot">
<EditItemTemplate>
<asp:DropDownList ID="DropDownList1" runat="server"
DataSourceID="dsSubPlotNames"
DataTextField="SiteID" DataValueField="SiteID"
SelectedValue='<%# Bind("SiteID") %>'
AppendDataBoundItems="True">
<asp:ListItem Value=""></asp:ListItem>
</asp:DropDownList>
<asp:SqlDataSource ID="dsSubPlotNames" runat="server"
ConnectionString="<%$ ConnectionStrings:WERCMTX %>" SelectCommand="exec [339_PPM].usp_SubPlotNames_Select @100mPlotSiteID;">
<SelectParameters>
<asp:Parameter Name="100mPlotSiteID" />
</SelectParameters>
</asp:SqlDataSource>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label3" runat="server" Text='<%# Bind("SubPlot")%>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
如您所见,参数名称“100mPlotSiteID”需要取自 100mPlot 列。我不确定如何再清楚地描述这一点,如果您有任何问题,请告诉我。感谢您的帮助。
使用新修订的代码进行编辑。这么近了!
<asp:TemplateField HeaderText="SubPlot" SortExpression="SubPlot">
<EditItemTemplate>
<asp:DropDownList ID="DropDownList1" runat="server"
DataSourceID="dsSubPlotNames"
DataTextField="SiteName" DataValueField="SiteID"
SelectedValue='<%# Bind("SiteID") %>'
>
</asp:DropDownList>
<asp:SqlDataSource ID="dsSubPlotNames" runat="server"
ConnectionString="<%$ ConnectionStrings:WERCMTX %>" SelectCommand='exec [339_PPM].usp_SubPlotNames_Select null, @100mPlotName;'
CancelSelectOnNullParameter="False">
<SelectParameters>
<asp:ControlParameter ControlID="GridView1" DefaultValue='<%# Eval("100mPlot") '
Name="100mPlotName" PropertyName="SelectedValue" />
</SelectParameters>
</asp:SqlDataSource>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label3" runat="server" Text='<%# Bind("SubPlot") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
不幸的是,我在 Eval("100mPlot") 中遇到了这个错误:
Databinding expressions are only supported on objects that have a DataBinding event. System.Web.UI.WebControls.ControlParameter does not have a DataBinding event.
最佳答案
您需要放置一个标签并将文本属性设置为'<%# Eval("100mPlot") %>'
并在数据源中使用控制参数。
如果标签的 id 是“label1”(必须在编辑项模板内)则使用此
<asp:ControlParameter ControlID="label1" PropertyName="Text" Name="100mPlotSiteID" />
关于c# - 将参数传递给绑定(bind)到 gridview 更新中的下拉列表的 sqldatasource,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10661493/
我有一个 SqlDataSource,我正在尝试向其添加 UpdateCommand,以便在选择 GridView 的更新按钮时调用存储过程。我在后面的代码中执行此操作,因为我需要调用两个过程之一,具
我正在使用 SqlDataSource 来填充 GridView。这是我的代码: private void DataCall() { //Object gets created for use
作为我在所有业务应用程序中使用的常用实用程序的一部分,我有这段代码... using System.Web.UI.WebControls; public class Database {
我在我的应用程序中使用 SqlDataSource 来填充下拉列表,我在 Visual Studio 的网页设计中配置它。 我希望这个下拉列表会根据 sql 中的几个表动态变化。 可以从代码中以编程方
使用 .NET 4 和 C#。所有这些都会引发错误: sdsTypeinfo.SelectParameters.Add("@TypeCode", DbType.Boolean, DBNull.Valu
我偶然发现了一个问题,无法自己解决。希望有人能帮我解决。 所以,我在 SQL Server 2005 数据库中有一个简单的存储过程 CREATE PROCEDURE spTest @pin var
我一直有这样的想法,与使用 SqlDataSource 编写 SQL 查询相比,在后面的代码中编写 SQL 查询并不好 SqlDataAdapter ad = new SqlDataAdapter("
如果网页需要一些数据,为什么不让 SQLDataSource 调用存储过程呢?为什么要使用 ObjectDataSource 调用业务对象,然后再调用存储过程?我知道基于 .net 框架构建的其他应用
是否有一种合理的方法可以从 SqlDataSource 获取预期参数列表(给定分配给其 SelectCommand 属性的存储过程的名称)? 最佳答案 您可以使用 SqlCommandBuilder.
我有以下 SqlDataSource " InsertCommand="INSERT INTO [Chat] ([Username], [Message]) VALUES (@User
我有一个 SqlDataSource 正在向我的 GridView 提供数据。这就是我在表单上使用的所有内容,因此我根本没有任何代码。但在某个地方我需要一个 TRY CATCH block ,以防万一
我是 ASP.net 的新手,目前正在阅读有关 SqlDataSource 的内容并正在运行一些示例。我正在与一位同事交谈,他说它“适用于快速和肮脏的应用程序”,但没有人会在生产/部署环境中使用它。
假设我在 .aspx 页面上有某种数据网格或转发器,并且我的数据源是内联定义的,如下所示: 如何调试我的代码,以便我可以准确地看到 Year 绑定(bin
所以我有一个 GridView 设置为 SqlDataSource。分页已启用,我有一个下拉菜单,可以更改每页显示的行数。我可以获得单个页面中显示的总行数,但我也想显示总行数。 (像这样:“显示 31
我正在创建一个 ASP.NET/C# 页面,用户在页面顶部输入一个 ID,当他们按下提交时,页面回发并显示数据。现在,数据字段始终显示 - 即使在页面加载且未进行搜索时也是如此。这并不理想,因为当他们
我有一个 FormView,下面有一个 UpdateButton 和一个 SqlDataSource。我的 updatebutton 总是用相同的值(我的 gridview 第一行的值)更新 Sil
我有一个绑定(bind)到 SqlDataSource 的 GridView。我在执行 UpdateCommand 时遇到问题,它似乎执行了两次。当我单步执行 gvChecklist_RowUpdat
我有一个带有 OnInserted 处理程序的 SqlDataSource。处理程序发送一封电子邮件,其中包含从 Inserted 记录中收集的数据。包括它的 ID(输出参数)。 昨天,我收到处理程序
我有一个 Microsoft SQL 数据库和一个 MySQL 数据库,我需要将它们加入并放入 GridView 中。 到目前为止,我已经成功地使用了 ASP 和 SqlDataSource,如下所示
我正在尝试按文本框名称 PostCode1 从 SQLDataSource POSTCODE_Data 中过滤数据。 我通过使用 .Rowfilter 属性来执行此操作,但它不起作用。结果 POSTC
我是一名优秀的程序员,十分优秀!