A
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" ////////////
<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>
<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);
}
/////////////////
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>
<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);
}
/////////////////