views:

135

answers:

1

I am creating a GridView/DetailsView page. I have a grid that displays a bunch of rows, when a row is selected it uses a DetailsView to allow for Insert/Update.

My question is what is the best way to link these? I do not want to reach out to the web service again, all the data i need is in the selected grid view row. I basically have 2 separate data sources that share the same "DataObjectTypeName", the first data source retrieves the data, and the other to do the CRUD.

What is the best way to transfer the Selected Grid View row to the Details View? Am I going to have to manualy handle the Insert/Update events and call the data source myself?

Is there no way to link these two so they use the same data source ?

  <asp:GridView ID="gvDetails" runat="server" DataKeyNames="ID, Code"
                DataSourceID="odsSearchData" >
   <Columns>
        <asp:BoundField DataField="RowA" HeaderText="A" SortExpression="RowA" />
        <asp:BoundField DataField="RowB" HeaderText="B" SortExpression="RowB" />
        <asp:BoundField DataField="RowC" HeaderText="C" SortExpression="RowC" />



    ....Code...

 <asp:DetailsView ID="dvDetails" runat="server" DataKeyNames="ID, Code"
                DataSourceID="odsCRUD" GridLines="None" DefaultMode="Edit" AutoGenerateRows="false"
                Visible="false" Width="100%">
         <Fields>
            <asp:BoundField DataField="RowA" HeaderText="A" SortExpression="RowA" />
           <asp:BoundField DataField="RowB" HeaderText="B" SortExpression="RowB" />
           <asp:BoundField DataField="RowC" HeaderText="C" SortExpression="RowC" />

...
A: 

The standard way to do it would be to have the selected item of the griview be a control parameter to the objectdatasource you have wired up to the detailsview. I would probably not worry too much about the overhead of retreiving data that you already have unless you are catering to users with such slow connections that you want to avoid roundtrips to the webserver at all costs.

If you really want to avoid that thenyou could pull the data out of the gridview using javascript/jquery and then do your inserts/updates via ajax calls. It would require lots more coding though.

Ben Robinson