简体   繁体   English

我更改了 ObjectDataSource 的 SelectMethod,但它仍然返回 GridView 上的旧值

[英]I changed ObjectDataSource's SelectMethod but it still returns old values on GridView

I have this two diferent classes to use in my ObjectDataSource:我在我的 ObjectDataSource 中使用了这两个不同的类:

"getColection" and "getLastColectionByUser" “getColection”和“getLastColectionByUser”

This is my ObjectDataSource at aspx.这是我在 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>`

If radio button selected value is "all" select method is "getColection" else is "getLastColectionByUser", all right?如果单选按钮选择的值是“all” select 方法是“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();`

When I debug it works fine.当我调试它工作正常。 The SelectMethod and SelectCountMethod are changing BUT the gridView is still showing old values. SelectMethod 和 SelectCountMethod 正在改变,但 gridView 仍然显示旧值。 The Classes are ok.课程还可以。 What is going wrong?出了什么问题?

You are probably changing the SelectMethod property after the ObjectDataSource is bound.您可能在绑定 ObjectDataSource 后更改 SelectMethod 属性。 Try adding ObjectDataSource1.DataBind();尝试添加ObjectDataSource1.DataBind(); at the end of the procedure you listed as a quick fix.在您列为快速修复的过程结束时。

What event handler is the code running in?代码在哪个事件处理程序中运行?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM