Logical / Technical Problem with ASP gridview and objectdatasooruce

Posted on 2011-10-20
Last Modified: 2012-05-12
Hi Experts

Here is my problem: I have two buttons Dispatch / Update. When I click on Update button I need to update the code for Provider. When I click on Dispatch button it doesnt update the code for Provider.

Is there any way that in ODS when I click on dispatch call the update function and then the dispatch function.

the ODS only support one Update Method. Is possible to have more that one with different names.

Any help will be appreciated

I have this code with the buttons

 <asp:Button ID="btnUpdate" Text="Update" runat="server" CommandArgument="Update"
            CommandName="Update" />
        <asp:Button ID="btnDispatch" Text="Dispatch" runat="server" CommandArgument="Dispatch"
            CommandName="Dispatch" />

Open in new window

Then I have this ODS:

<asp:ObjectDataSource ID="odsDetail" runat="server" TypeName="DataAccess.WorkOrder"
    SelectMethod="getWODetails" UpdateMethod="updateWODetails">
        <asp:QueryStringParameter Name="WONum" Type="String" QueryStringField="WONum" />
        <asp:QueryStringParameter Name="SiteID" Type="String" QueryStringField="SiteID" />
        <asp:QueryStringParameter Name="OrgID" Type="String" QueryStringField="OrgID" />
        <asp:QueryStringParameter QueryStringField="WoNum" Name="WoNum" Type="String" />
        <asp:QueryStringParameter Name="SiteId" Type="String" QueryStringField="SiteID" />
        <asp:Parameter Name="description" Type="String" />
        <asp:Parameter Name="WLoc" Type="String" />
        <asp:Parameter Name="AssetNum" Type="String" />
        <asp:Parameter Name="woPriority" Type="String" />
        <asp:Parameter Name="worktype" Type="String" />
        <asp:Parameter Name="details" Type="String" />
        <asp:Parameter Name="Location" Type="String" />
        <asp:Parameter Name="Asset" Type="String" />
        <asp:Parameter Name="Priority" Type="String" />
        <asp:Parameter Name="reportedby" Type="String" />
        <asp:Parameter Name="ProjNum" Type="String" />
        <asp:Parameter Name="reportdate" Type="String" />
        <asp:Parameter Name="provider" Type="String" />

Open in new window

Finally the code that Updates the DB

case "Update":
                    string updmsg = string.Format("Work Order {0} has been updated successfully", Request.QueryString["WONum"]);
                    imsg.ShowMsg(updmsg, false); 
                case "Dispatch":
                    (new DataAccess.WorkOrder()).updateWOStatus(Request.QueryString["WONum"],"INPRG", Request.QueryString["SiteID"], Request.QueryString["OrgID"], (fvDetail.FindControl("txtreportedby") as RadTextBox).Text);
                    //Page.ClientScript.RegisterStartupScript(Page.GetType(), "mykey", "CloseAndRebind();", true);
                    string dismsg = string.Format("Work Order {0} has been dispatched successfully", Request.QueryString["WONum"]);
                    imsg.ShowMsg(dismsg, true);

Open in new window

Question by:JoseHidalgo
    LVL 20

    Accepted Solution

    It seems that you are saying when you click "dispatch" you want the original update function to fire but then you want a second and seperate dispatch update to fire.

    A really simple "point-out" is that if a button in a GridView has a CommandArg="Update" then it will automatically fire its datasource's Update function. So if you set both your button's CommandArgs to "Update" it should fire the update for either one.

    The problem is you seem to be using your commandarg to make other distinctions so then you have to figure out how to make these distinctions in another way or look at another approach.

    You asked "Is there a way in ODS to call update then dispatch function?":

    You can call your update function during the Gridview.RowCommand or the specific dispatch button's event by using the GridView.RowUpdate() method.

    See the 1st example here:

    You pointed out the the ODS has only one update method and asked if there was a way to have multiples:

    Well you could write multiple update statements on your object or somewhere in code behind. Then during the RowCommand event you can programmatically access and change the attributes of the ODS to point to a different method and if necessary change the ODS parameters as well.

            odsDetail.UpdateMethod = "new method name";
            odsDetail.UpdateParameters.Add(new QueryStringParameter("multiple", options, here));

    When your done fire the UpdateRow() method again.

    There's a lot going on here and so I can't get crazy specific without writing a ton of code, but I hope this can give you some direction. What you are trying to do is possible. In my past experience messing around with datasources programmatically can get a bit tedious to get it all ironed out.

    Author Closing Comment


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Suggested Solutions

    Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
    Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
    Here's a very brief overview of the methods PRTG Network Monitor ( offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
    Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

    779 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    9 Experts available now in Live!

    Get 1:1 Help Now