GridView-FormView/Master-Detail with ObjectDataSource

Discussion in 'ASP .Net' started by Aamir Ghanchi, Jan 18, 2008.

  1. Hi,

    I find it amazing that there is no single example over the web that
    discusses how to use Master(Gridview) and Detail (FormView) model
    using objectdatasource and the whole nine yards Edit/Insert also.
    There is one availabe with DetailsView.

    If any one has a link, then please send it my way. I'll appreciate it

    The problem I am having is that Formview's EditItemTemplate does not
    appear when a Select command button is clicked on a row in Gridview.
    In the selectedIndex changed event of gridview, I am changing the
    FormViewMode to Edit:
    FormView1.ChangeMode(FormViewMode.Edit); I'm doubling it in the
    Selected event handler of the Formview's objectdatasource.

    The the select paramater of objectdatasource to which the FormView is
    bind has a Control parameter that gets its value from the
    SelectedValue property of GridView.

    I have been tracing the code . The Selected event of FormView's
    objectdatasource fires. The DataBound event of Formview fires.

    I am not sure what am I missing?

    /////// aspx code "Test.aspx" ////////////
    <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="True"
    DataKeyNames="ExperienceID" DataSourceID="objdsGridView"
    OnSelectedIndexChanged="GridView1_SelectedIndexChanged"
    OnSelectedIndexChanging="GridView1_SelectedIndexChanging">
    <Columns>
    <asp:CommandField ShowSelectButton="True" />
    </Columns>
    </asp:GridView>
    <br />
    <asp:FormView ID="FormView1" runat="server" DataKeyNames="RecID"
    DataSourceID="objdsFormView" DefaultMode="Insert"
    OnDataBound="FormView1_DataBound"
    OnModeChanged="FormView1_ModeChanged"
    OnPageIndexChanging="FormView1_PageIndexChanging"
    OnPreRender="FormView1_PreRender">
    <EditItemTemplate>
    <h2>Edit mode</h2>
    <div class="DataItem">
    <label>Company Name</label>
    <div>
    <asp:TextBox ID="txtCompany" runat="server" Text='<
    %#Bind("Company")%>' Width="40%"></asp:TextBox>
    </div>
    </div>
    </EditItemTemplate>
    <InsertItemTemplate>
    <h2>Insert mode</h2>

    <div class="DataItem">
    <label>
    Company Name</label>
    <div>
    <asp:TextBox ID="txtCompany" runat="server" Width="40%"></
    asp:TextBox>
    </div>
    </div>
    </InsertItemTemplate>

    <EmptyDataTemplate>
    Empty Template
    </EmptyDataTemplate>

    </asp:FormView>
    &nbsp;<br />
    <asp:ObjectDataSource ID="objdsGridView" runat="server"
    OnSelected="objdsGridView_Selected" SelectMethod="GetAllRecords"
    TypeName="MyNameSpace.MyBusinessObject"></asp:ObjectDataSource>
    <asp:ObjectDataSource ID="objdsFormView" runat="server"
    OnSelected="objdsFormView_Selected" SelectMethod="GetASinglRecord"
    TypeName="MyNameSpace.MyBusinessObject" UpdateMethod="UpdateARecord">
    <SelectParameters>
    <asp:ControlParameter ControlID="GridView1" Name="RecID"
    PropertyName="SelectedValue" />
    </SelectParameters>
    </asp:ObjectDataSource>

    ////////////// Code Behind "Test.aspx.cs" ////////////////////////////

    protected void objdsFormView_Selected(object sender,
    ObjectDataSourceStatusEventArgs e)
    {
    Trace.Warn(System.Reflection.MethodBase.GetCurrentMethod().Name);
    FormView1.ChangeMode(FormViewMode.Edit);
    Trace.Warn(" FormView1.CurrentMode=" +
    FormView1.CurrentMode.ToString());
    }

    protected void GridView1_SelectedIndexChanged(object sender, EventArgs
    e)
    {
    Trace.Warn(System.Reflection.MethodBase.GetCurrentMethod().Name);

    FormView1.ChangeMode(FormViewMode.Edit);
    }

    /////////////////
     
    Aamir Ghanchi, Jan 18, 2008
    #1
    1. Advertising

  2. Hi I am the original poster. One more update on this.

    The template its displaying instead of EditItemTemplate is
    EmptyDataTemplate.
    As I have the Trace on, it shows the FormView Mode still as Edit in
    the FormView1_PreRender event handler.

    On Jan 18, 3:52 pm, Aamir Ghanchi <> wrote:
    > Hi,
    >
    > I find it amazing that there is no single example over the web that
    > discusses how to use Master(Gridview)  and Detail (FormView) model
    > using objectdatasource and the whole nine yards Edit/Insert also.
    > There is one availabe with DetailsView.
    >
    > If any one has a link, then please send it my way. I'll appreciate it
    >
    > The problem I am having is that Formview's EditItemTemplate does not
    > appear when a Select command button is clicked on a row in Gridview.
    > In the selectedIndex changed event of gridview, I am changing the
    > FormViewMode to Edit:
    > FormView1.ChangeMode(FormViewMode.Edit); I'm doubling it in the
    > Selected event handler of the Formview's objectdatasource.
    >
    > The the select paramater of objectdatasource to which the FormView is
    > bind has a Control parameter that gets its value from the
    > SelectedValue property of GridView.
    >
    > I have been tracing the code . The Selected event of FormView's
    > objectdatasource fires. The DataBound event of Formview fires.
    >
    > I am not sure what am I missing?
    >
    > /////// aspx code "Test.aspx" ////////////
    > <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="True"
    > DataKeyNames="ExperienceID" DataSourceID="objdsGridView"
    > OnSelectedIndexChanged="GridView1_SelectedIndexChanged"
    > OnSelectedIndexChanging="GridView1_SelectedIndexChanging">
    >                         <Columns>
    >                                 <asp:CommandField ShowSelectButton="True" />
    >                         </Columns>
    >                 </asp:GridView>
    >                 <br />
    >                 <asp:FormView ID="FormView1" runat="server" DataKeyNames="RecID"
    > DataSourceID="objdsFormView" DefaultMode="Insert"
    > OnDataBound="FormView1_DataBound"
    > OnModeChanged="FormView1_ModeChanged"
    > OnPageIndexChanging="FormView1_PageIndexChanging"
    > OnPreRender="FormView1_PreRender">
    >                         <EditItemTemplate>
    >                                 <h2>Edit mode</h2>
    >                                 <div class="DataItem">
    >                                         <label>Company Name</label>
    >                                         <div>
    >                                                 <asp:TextBox ID="txtCompany" runat="server" Text='<
    > %#Bind("Company")%>' Width="40%"></asp:TextBox>
    >                                         </div>
    >                                 </div>
    >                         </EditItemTemplate>
    >                         <InsertItemTemplate>
    >                                 <h2>Insert mode</h2>
    >
    >                                 <div class="DataItem">
    >                                         <label>
    >                                                 Company Name</label>
    >                                         <div>
    >                                                 <asp:TextBox ID="txtCompany" runat="server" Width="40%"></
    > asp:TextBox>
    >                                         </div>
    >                                 </div>
    >                         </InsertItemTemplate>
    >
    >                         <EmptyDataTemplate>
    >                                 Empty Template
    >                         </EmptyDataTemplate>
    >
    >                 </asp:FormView>
    >                 &nbsp;<br />
    >                 <asp:ObjectDataSource ID="objdsGridView" runat="server"
    > OnSelected="objdsGridView_Selected" SelectMethod="GetAllRecords"
    > TypeName="MyNameSpace.MyBusinessObject"></asp:ObjectDataSource>
    >                 <asp:ObjectDataSource ID="objdsFormView" runat="server"
    > OnSelected="objdsFormView_Selected" SelectMethod="GetASinglRecord"
    > TypeName="MyNameSpace.MyBusinessObject" UpdateMethod="UpdateARecord">
    >                         <SelectParameters>
    >                                 <asp:ControlParameter ControlID="GridView1" Name="RecID"
    > PropertyName="SelectedValue" />
    >                         </SelectParameters>
    >                 </asp:ObjectDataSource>
    >
    > ////////////// Code Behind "Test.aspx.cs" ////////////////////////////
    >
    > protected void objdsFormView_Selected(object sender,
    > ObjectDataSourceStatusEventArgs e)
    >         {
    >                 Trace.Warn(System.Reflection.MethodBase.GetCurrentMethod().Name);
    >                 FormView1.ChangeMode(FormViewMode.Edit);
    >                 Trace.Warn("   FormView1.CurrentMode=" +
    > FormView1.CurrentMode.ToString());
    >         }
    >
    > protected void GridView1_SelectedIndexChanged(object sender, EventArgs
    > e)
    >         {
    >                 Trace.Warn(System.Reflection.MethodBase.GetCurrentMethod().Name);
    >
    >                 FormView1.ChangeMode(FormViewMode.Edit);
    >         }
    >
    > /////////////////
     
    Aamir Ghanchi, Jan 18, 2008
    #2
    1. Advertising

  3. My bad :(
    I was not returning the "this" object from the SelectMethod of the
    ObjectDataSource Class.
    sorry for the confusion.

    On Jan 18, 5:08 pm, Aamir Ghanchi <> wrote:
    > Hi I am the original poster. One more update on this.
    >
    > The template its displaying instead of EditItemTemplate is
    > EmptyDataTemplate.
    > As I have the Trace on, it shows the FormView Mode still as Edit in
    > the FormView1_PreRender event handler.
    >
    > On Jan 18, 3:52 pm, Aamir Ghanchi <> wrote:
    >
    >
    >
    > > Hi,

    >
    > > I find it amazing that there is no single example over the web that
    > > discusses how to use Master(Gridview)  and Detail (FormView) model
    > > using objectdatasource and the whole nine yards Edit/Insert also.
    > > There is one availabe with DetailsView.

    >
    > > If any one has a link, then please send it my way. I'll appreciate it

    >
    > > The problem I am having is that Formview's EditItemTemplate does not
    > > appear when a Select command button is clicked on a row in Gridview.
    > > In the selectedIndex changed event of gridview, I am changing the
    > > FormViewMode to Edit:
    > > FormView1.ChangeMode(FormViewMode.Edit); I'm doubling it in the
    > > Selected event handler of the Formview's objectdatasource.

    >
    > > The the select paramater of objectdatasource to which the FormView is
    > > bind has a Control parameter that gets its value from the
    > > SelectedValue property of GridView.

    >
    > > I have been tracing the code . The Selected event of FormView's
    > > objectdatasource fires. The DataBound event of Formview fires.

    >
    > > I am not sure what am I missing?

    >
    > > /////// aspx code "Test.aspx" ////////////
    > > <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="True"
    > > DataKeyNames="ExperienceID" DataSourceID="objdsGridView"
    > > OnSelectedIndexChanged="GridView1_SelectedIndexChanged"
    > > OnSelectedIndexChanging="GridView1_SelectedIndexChanging">
    > >                         <Columns>
    > >                                 <asp:CommandField ShowSelectButton="True" />
    > >                         </Columns>
    > >                 </asp:GridView>
    > >                 <br />
    > >                 <asp:FormView ID="FormView1" runat="server" DataKeyNames="RecID"
    > > DataSourceID="objdsFormView" DefaultMode="Insert"
    > > OnDataBound="FormView1_DataBound"
    > > OnModeChanged="FormView1_ModeChanged"
    > > OnPageIndexChanging="FormView1_PageIndexChanging"
    > > OnPreRender="FormView1_PreRender">
    > >                         <EditItemTemplate>
    > >                                 <h2>Edit mode</h2>
    > >                                 <div class="DataItem">
    > >                                         <label>Company Name</label>
    > >                                         <div>
    > >                                                 <asp:TextBox ID="txtCompany" runat="server" Text='<
    > > %#Bind("Company")%>' Width="40%"></asp:TextBox>
    > >                                         </div>
    > >                                 </div>
    > >                         </EditItemTemplate>
    > >                         <InsertItemTemplate>
    > >                                 <h2>Insert mode</h2>

    >
    > >                                 <div class="DataItem">
    > >                                         <label>
    > >                                                 Company Name</label>
    > >                                         <div>
    > >                                                 <asp:TextBox ID="txtCompany" runat="server" Width="40%"></
    > > asp:TextBox>
    > >                                         </div>
    > >                                 </div>
    > >                         </InsertItemTemplate>

    >
    > >                         <EmptyDataTemplate>
    > >                                 Empty Template
    > >                         </EmptyDataTemplate>

    >
    > >                 </asp:FormView>
    > >                 &nbsp;<br />
    > >                 <asp:ObjectDataSource ID="objdsGridView" runat="server"
    > > OnSelected="objdsGridView_Selected" SelectMethod="GetAllRecords"
    > > TypeName="MyNameSpace.MyBusinessObject"></asp:ObjectDataSource>
    > >                 <asp:ObjectDataSource ID="objdsFormView" runat="server"
    > > OnSelected="objdsFormView_Selected" SelectMethod="GetASinglRecord"
    > > TypeName="MyNameSpace.MyBusinessObject" UpdateMethod="UpdateARecord">
    > >                         <SelectParameters>
    > >                                 <asp:ControlParameter ControlID="GridView1" Name="RecID"
    > > PropertyName="SelectedValue" />
    > >                         </SelectParameters>
    > >                 </asp:ObjectDataSource>

    >
    > > ////////////// Code Behind "Test.aspx.cs" ////////////////////////////

    >
    > > protected void objdsFormView_Selected(object sender,
    > > ObjectDataSourceStatusEventArgs e)
    > >         {
    > >                 Trace.Warn(System.Reflection.MethodBase.GetCurrentMethod().Name);
    > >                 FormView1.ChangeMode(FormViewMode.Edit);
    > >                 Trace.Warn("   FormView1.CurrentMode=" +
    > > FormView1.CurrentMode.ToString());
    > >         }

    >
    > > protected void GridView1_SelectedIndexChanged(object sender, EventArgs
    > > e)
    > >         {
    > >                 Trace.Warn(System.Reflection.MethodBase.GetCurrentMethod().Name);

    >
    > >                 FormView1.ChangeMode(FormViewMode.Edit);
    > >         }

    >
    > > /////////////////- Hide quoted text -

    >
    > - Show quoted text -
     
    Aamir Ghanchi, Jan 18, 2008
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. asmj
    Replies:
    0
    Views:
    510
  2. yixiang
    Replies:
    1
    Views:
    2,582
    Milosz Skalecki [MCAD]
    Jan 29, 2008
  3. Henri Fournier

    FormView/ListView master/detail problem

    Henri Fournier, Mar 6, 2009, in forum: ASP .Net
    Replies:
    0
    Views:
    1,803
    Henri Fournier
    Mar 6, 2009
  4. Arun Kumar Menon

    Master Detail detail

    Arun Kumar Menon, Aug 6, 2003, in forum: ASP .Net Datagrid Control
    Replies:
    0
    Views:
    205
    Arun Kumar Menon
    Aug 6, 2003
  5. Frederik Borg

    ASp.net data binding: Master-detail-detail

    Frederik Borg, Jun 9, 2006, in forum: ASP .Net Datagrid Control
    Replies:
    0
    Views:
    363
    Frederik Borg
    Jun 9, 2006
Loading...

Share This Page