• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 235
  • Last Modified:

Logical / Technical Problem with ASP gridview and objectdatasooruce

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">
    <SelectParameters>
        <asp:QueryStringParameter Name="WONum" Type="String" QueryStringField="WONum" />
        <asp:QueryStringParameter Name="SiteID" Type="String" QueryStringField="SiteID" />
        <asp:QueryStringParameter Name="OrgID" Type="String" QueryStringField="OrgID" />
    </SelectParameters>
    <UpdateParameters>
        <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" />
    </UpdateParameters>
</asp:ObjectDataSource>

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); 
                    break;
                
                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);
                    break;

Open in new window

0
JoseHidalgo
Asked:
JoseHidalgo
1 Solution
 
ddayx10Commented:
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.

http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.gridview.rowcommand.aspx

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:
http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.gridview.updaterow.aspx

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.Clear();
        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.
0
 
JoseHidalgoAuthor Commented:
Thanks
0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now