【问题标题】:I changed ObjectDataSource's SelectMethod but it still returns old values on GridView我更改了 ObjectDataSource 的 SelectMethod,但它仍然在 GridView 上返回旧值
【发布时间】:2011-06-10 19:44:13
【问题描述】:

我的 ObjectDataSource 中有这两个不同的类:

“getColection”和“getLastColectionByUser”

这是我在 aspx 的 ObjectDataSource。

`

  <asp:ObjectDataSource ID="ObjectDataSource1" runat="server"          SelectMethod="getColection"TypeName="HepatiteNegocio.ViewProtocoloCol" SelectCountMethod="getColectionCount"
    EnablePaging="True">
    <SelectParameters>
        <asp:Parameter Name="pWhere" Type="String" />
        <asp:Parameter Name="pOrderBY" Type="String" />
        <asp:Parameter Name="startRowIndex" Type="Int32" />
        <asp:Parameter Name="maximumRows" Type="Int32" />
    </SelectParameters>
</asp:ObjectDataSource>`

如果单选按钮选择的值为“all”,则选择方法为“getColection”,否则为“getLastColectionByUser”,好吗?

          `if(radioButton.SelectedValue.Equals("all"))
        {
            ObjectDataSource1.SelectMethod = "getColection";
            ObjectDataSource1.SelectCountMethod = "getColectionCount";

            try
            {
                validation();

                ObjectDataSource1.SelectParameters[0].DefaultValue = getWhere();
                ObjectDataSource1.SelectParameters[1].DefaultValue = "protocolNumber";

            }
            catch
            {
                set an error message
            }
        }
        else  
        {
            ObjectDataSource1.SelectMethod = "getLastColectionByUser";
            ObjectDataSource1.SelectCountMethod = "getLastCountColectionByUser";
            try
            {
                validation();
                ObjectDataSource1.SelectParameters[0].DefaultValue = getWhere();
                ObjectDataSource1.SelectParameters[1].DefaultValue = "protocolNumber";
            }
            catch
            {
                set an erron message
            }
        } 
        ObjectDataSource1.DataBind();
        GridView1.DataBind();`

当我调试它工作正常。 SelectMethod 和 SelectCountMethod 正在改变,但 gridView 仍然显示旧值。课程还可以。出了什么问题?

【问题讨论】:

  • 这段代码显然无法编译——我不相信它可以在调试中正常工作。
  • 太好了——你取消了我的更改。这个问题我放弃了

标签: c# asp.net gridview objectdatasource selectmethod


【解决方案1】:

您可能在绑定 ObjectDataSource 后更改 SelectMethod 属性。尝试在您列为快速修复的过程末尾添加ObjectDataSource1.DataBind();

代码在哪个事件处理程序中运行?

【讨论】:

  • 我在代码末尾绑定了 ObjectDataSource 和 GridView。我在页面加载和 radioButton_OnselectedChanged 方法中执行此操作。
猜你喜欢
  • 2018-07-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-12-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多