GridView-FormView/Master-Detail with ObjectDataSource

GridView-FormView/Master-Detail with ObjectDataSource

am 18.01.2008 22:52:24 von Aamir Ghanchi

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" ////////////
DataKeyNames="ExperienceID" DataSourceID="objdsGridView"
OnSelectedIndexChanged="GridView1_SelectedIndexChanged"
OnSelectedIndexChanging="GridView1_SelectedIndexChanging">






DataSourceID="objdsFormView" DefaultMode="Insert"
OnDataBound="FormView1_DataBound"
OnModeChanged="FormView1_ModeChanged"
OnPageIndexChanging="FormView1_PageIndexChanging"
OnPreRender="FormView1_PreRender">

Edit mode










Insert mode






asp:TextBox>





Empty Template



 

OnSelected="objdsGridView_Selected" SelectMethod="GetAllRecords"
TypeName="MyNameSpace.MyBusinessObject">

OnSelected="objdsFormView_Selected" SelectMethod="GetASinglRecord"
TypeName="MyNameSpace.MyBusinessObject" UpdateMethod="UpdateARecord">

PropertyName="SelectedValue" />



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

protected void objdsFormView_Selected(object sender,
ObjectDataSourceStatusEventArgs e)
{
Trace.Warn(System.Reflection.MethodBase.GetCurrentMethod().N ame);
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().N ame);

FormView1.ChangeMode(FormViewMode.Edit);
}

/////////////////

Re: GridView-FormView/Master-Detail with ObjectDataSource

am 19.01.2008 00:08:53 von Aamir Ghanchi

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=A0pm, Aamir Ghanchi wrote:
> Hi,
>
> I find it amazing that there is no single example over the web that
> discusses how to use Master(Gridview) =A0and 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" ////////////
> e"
> DataKeyNames=3D"ExperienceID" DataSourceID=3D"objdsGridView"
> OnSelectedIndexChanged=3D"GridView1_SelectedIndexChanged"
> OnSelectedIndexChanging=3D"GridView1_SelectedIndexChanging">
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 ndField ShowSelectButton=3D"True" />
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0

> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0

> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0

> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 rver" DataKeyNames=3D"RecID"
> DataSourceID=3D"objdsFormView" DefaultMode=3D"Insert"
> OnDataBound=3D"FormView1_DataBound"
> OnModeChanged=3D"FormView1_ModeChanged"
> OnPageIndexChanging=3D"FormView1_PageIndexChanging"
> OnPreRender=3D"FormView1_PreRender">
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0

Edit m=
ode


> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0
=3D"DataItem">
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =
=A0 =A0
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =
=A0 =A0

> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =
=A0 =A0 =A0 =A0 =A0 =A0 =3D'<
> %#Bind("Company")%>' Width=3D"40%">

> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =
=A0 =A0

> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0

> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0

Insert=
mode


>
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0
=3D"DataItem">
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =
=A0 =A0
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =
=A0 =A0

> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =
=A0 =A0 =A0 =A0 =A0 =A0 h=3D"40%"> > asp:TextBox>
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =
=A0 =A0

> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0

> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0

>
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 Empty Temp=
late
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0

>
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0  

> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 runat=3D"server"
> OnSelected=3D"objdsGridView_Selected" SelectMethod=3D"GetAllRecords"
> TypeName=3D"MyNameSpace.MyBusinessObject">

> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 runat=3D"server"
> OnSelected=3D"objdsFormView_Selected" SelectMethod=3D"GetASinglRecord"
> TypeName=3D"MyNameSpace.MyBusinessObject" UpdateMethod=3D"UpdateARecord">
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 olParameter ControlID=3D"GridView1" Name=3D"RecID"
> PropertyName=3D"SelectedValue" />
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0

> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0

>
> ////////////// Code Behind "Test.aspx.cs" ////////////////////////////
>
> protected void objdsFormView_Selected(object sender,
> ObjectDataSourceStatusEventArgs e)
> =A0 =A0 =A0 =A0 {
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 Trace.Warn(System.Reflection.MethodBase.Ge=
tCurrentMethod().Name);
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 FormView1.ChangeMode(FormViewMode.Edit);
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 Trace.Warn(" =A0 FormView1.CurrentMode=3D"=
+
> FormView1.CurrentMode.ToString());
> =A0 =A0 =A0 =A0 }
>
> protected void GridView1_SelectedIndexChanged(object sender, EventArgs
> e)
> =A0 =A0 =A0 =A0 {
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 Trace.Warn(System.Reflection.MethodBase.Ge=
tCurrentMethod().Name);
>
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 FormView1.ChangeMode(FormViewMode.Edit);
> =A0 =A0 =A0 =A0 }
>
> /////////////////

Re: GridView-FormView/Master-Detail with ObjectDataSource

am 19.01.2008 00:49:14 von Aamir Ghanchi

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=A0pm, 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=A0pm, Aamir Ghanchi wrote:
>
>
>
> > Hi,
>
> > I find it amazing that there is no single example over the web that
> > discusses how to use Master(Gridview) =A0and 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" ////////////
> > rue"
> > DataKeyNames=3D"ExperienceID" DataSourceID=3D"objdsGridView"
> > OnSelectedIndexChanged=3D"GridView1_SelectedIndexChanged"
> > OnSelectedIndexChanging=3D"GridView1_SelectedIndexChanging">
> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0
> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 mandField ShowSelectButton=3D"True" />
> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0

> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0

> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0

> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 server" DataKeyNames=3D"RecID"
> > DataSourceID=3D"objdsFormView" DefaultMode=3D"Insert"
> > OnDataBound=3D"FormView1_DataBound"
> > OnModeChanged=3D"FormView1_ModeChanged"
> > OnPageIndexChanging=3D"FormView1_PageIndexChanging"
> > OnPreRender=3D"FormView1_PreRender">
> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0
> >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=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =
=A0 =A0 =A0 =A0 =A0 =A0 h=3D"40%"> > > asp:TextBox>
> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =
=A0 =A0

> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0

> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0

>
> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0
> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 Empty Te=
mplate
> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0

>
> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0
> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0  

> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 w" runat=3D"server"
> > OnSelected=3D"objdsGridView_Selected" SelectMethod=3D"GetAllRecords"
> > TypeName=3D"MyNameSpace.MyBusinessObject">

> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 w" runat=3D"server"
> > OnSelected=3D"objdsFormView_Selected" SelectMethod=3D"GetASinglRecord"
> > TypeName=3D"MyNameSpace.MyBusinessObject" UpdateMethod=3D"UpdateARecord"=
>
> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0
> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 trolParameter ControlID=3D"GridView1" Name=3D"RecID"
> > PropertyName=3D"SelectedValue" />
> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0

> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0

>
> > ////////////// Code Behind "Test.aspx.cs" ////////////////////////////
>
> > protected void objdsFormView_Selected(object sender,
> > ObjectDataSourceStatusEventArgs e)
> > =A0 =A0 =A0 =A0 {
> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 Trace.Warn(System.Reflection.MethodBase.=
GetCurrentMethod().Name);
> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 FormView1.ChangeMode(FormViewMode.Edit);=

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

> > =A0 =A0 =A0 =A0 }
>
> > /////////////////- Hide quoted text -
>
> - Show quoted text -