views:

19

answers:

1

I want my Formview to start in Insert mode and then change to Edit mode when a user selects a row from the Gridview in the same page.

The Formview has the inline attribute: DefaultMode="Insert"

How can this be done and why isn't this working?

protected void GridView1_SelectedIndexChanged(object sender, System.EventArgs e)   
{   
    FormView1.ChangeMode(FormViewMode.Edit);
} 

Edit1: FormView Source code

<asp:FormView ID="FormView1" runat="server" DataKeyNames="AdID" DataSourceID="AdByID" DefaultMode="Insert">
<EditItemTemplate>
    Caption:
    <asp:TextBox ID="CaptionTextBox" runat="server" Text='<%# Bind("Caption") %>' />
    <br />
    Summary:
    <asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("Summary") %>'></asp:TextBox>
    <br />
    Text:
    <telerik:RadEditor ID="RadEditor1" Runat="server" Content='<%# Bind("Text") %>' ToolsFile="~/crm/annonser/ToolsFile.xml"  
        Language="sv-SE" ToolbarMode="Default" 
        AllowScripts="True" EditModes="Design" Skin="Office2007" 
        StripFormattingOnPaste="MSWord" Width="500px">
        <Content>
        </Content>
    </telerik:RadEditor>
    <br />
    Name:
    <asp:TextBox ID="NameTextBox" runat="server" Text='<%# Bind("Name") %>' />
    <br />
    Email:
    <asp:TextBox ID="EmailTextBox" runat="server" Text='<%# Bind("Email") %>' />
    <br />
    Phone:
    <asp:TextBox ID="PhoneTextBox" runat="server" Text='<%# Bind("Phone") %>' />
    <br />
    PhoneHidden:
    <asp:CheckBox ID="PhoneHiddenCheckBox" runat="server" 
        Checked='<%# Bind("PhoneHidden") %>' />
    <br />
    Price:
    <asp:TextBox ID="PriceTextBox" runat="server" Text='<%# Bind("Price") %>' />
    <br />
    CategoryCodeID:
    <asp:DropDownList ID="DropDownList2" runat="server" 
        DataSourceID="AdCategoryMarket" DataTextField="Caption" 
        DataValueField="AdCategoryCodeID" SelectedValue='<%# Bind("CategoryCodeID") %>'>
    </asp:DropDownList>
    <asp:ObjectDataSource ID="AdCategoryMarket" runat="server" 
        DeleteMethod="Delete" InsertMethod="Insert" 
        OldValuesParameterFormatString="original_{0}" SelectMethod="GetData" 
        TypeName="dsCRMTableAdapters.app_AdCategoryCodeTableAdapter" 
        UpdateMethod="Update">
        <DeleteParameters>
            <asp:Parameter Name="Original_AdCategoryCodeID" Type="Int32" />
        </DeleteParameters>
        <InsertParameters>
            <asp:Parameter Name="Caption" Type="String" />
            <asp:Parameter Name="DisplayOrder" Type="Int32" />
            <asp:Parameter Name="CategoryTypeID" Type="Int32" />
        </InsertParameters>
        <UpdateParameters>
            <asp:Parameter Name="Caption" Type="String" />
            <asp:Parameter Name="DisplayOrder" Type="Int32" />
            <asp:Parameter Name="CategoryTypeID" Type="Int32" />
            <asp:Parameter Name="Original_AdCategoryCodeID" Type="Int32" />
        </UpdateParameters>
    </asp:ObjectDataSource>
    <br />
    StateCodeID:
    <asp:DropDownList ID="DropDownList3" runat="server" DataSourceID="AdStateCode" 
        DataTextField="Caption" DataValueField="AdStateCodeID" 
        SelectedValue='<%# Bind("StateCodeID") %>'>
    </asp:DropDownList>
    <asp:ObjectDataSource ID="AdStateCode" runat="server" DeleteMethod="Delete" 
        InsertMethod="Insert" OldValuesParameterFormatString="original_{0}" 
        SelectMethod="GetData" 
        TypeName="dsCRMTableAdapters.app_AdStateCodeTableAdapter" UpdateMethod="Update">
        <DeleteParameters>
            <asp:Parameter Name="Original_AdStateCodeID" Type="Byte" />
        </DeleteParameters>
        <InsertParameters>
            <asp:Parameter Name="Caption" Type="String" />
        </InsertParameters>
        <UpdateParameters>
            <asp:Parameter Name="Caption" Type="String" />
            <asp:Parameter Name="Original_AdStateCodeID" Type="Byte" />
        </UpdateParameters>
    </asp:ObjectDataSource>
    <br />
    RegionCodeID:
    <asp:DropDownList ID="DropDownList1" runat="server" DataSourceID="Regions" 
        DataTextField="name" DataValueField="RegionCodeID" 
        SelectedValue='<%# Bind("RegionCodeID") %>'>
    </asp:DropDownList>
    <asp:ObjectDataSource ID="Regions" runat="server" 
        OldValuesParameterFormatString="original_{0}" SelectMethod="GetData" 
        TypeName="dsCRMTableAdapters.app_RegionCodeTableAdapter">
    </asp:ObjectDataSource>
    <br />
    StopDate:
    <telerik:RadDatePicker ID="RadDatePicker1" Runat="server" Culture="sv-SE" 
        DbSelectedDate='<%# Bind("StopDate") %>'>
    </telerik:RadDatePicker>
    <br />
    <br />
    <asp:LinkButton ID="InsertButton" runat="server" CommandName="Insert" Text="Insert" />
    &nbsp;
    <asp:LinkButton ID="UpdateButton" runat="server" CommandName="Update" Text="Update" CommandArgument='<%# Eval("AdID") %>' />
    &nbsp;
    <asp:LinkButton ID="UpdateCancelButton" runat="server" CausesValidation="False" CommandName="Cancel" Text="Cancel" />
</EditItemTemplate></asp:FormView>

FormView DataSource

<asp:ObjectDataSource ID="AdByID" runat="server"  
OldValuesParameterFormatString="original_{0}" SelectMethod="GetDataByID" 
TypeName="dsCRMTableAdapters.app_AdTableAdapter" DeleteMethod="Delete" 
InsertMethod="Insert" UpdateMethod="Update">
<DeleteParameters>
    <asp:Parameter Name="Original_AdID" Type="Int32" />
</DeleteParameters>
<InsertParameters>
    <asp:Parameter Name="Caption" Type="String" />
    <asp:Parameter Name="Summary" Type="String" />
    <asp:Parameter Name="Text" Type="String" />
    <asp:Parameter Name="Name" Type="String" />
    <asp:Parameter Name="Email" Type="String" />
    <asp:Parameter Name="Phone" Type="String" />
    <asp:Parameter Name="PhoneHidden" Type="Boolean" />
    <asp:Parameter Name="Price" Type="Decimal" />
    <asp:Parameter Name="CategoryCodeID" Type="Byte" />
    <asp:Parameter Name="StateCodeID" Type="Byte" />
    <asp:Parameter Name="RegionCodeID" Type="Byte" />
    <asp:Parameter Name="StopDate" Type="DateTime" />
    <asp:Parameter Name="ModifiedBy" Type="Int32" />
    <asp:Parameter Name="CreatedOn" Type="DateTime" />
    <asp:Parameter Name="ModifiedOn" Type="DateTime" />
    <asp:Parameter DbType="Guid" Name="AdGUID" />
</InsertParameters>
<SelectParameters>
    <asp:ControlParameter ControlID="GridView1" Name="AdID" PropertyName="SelectedValue" Type="Int32" DefaultValue="0" />
</SelectParameters>
<UpdateParameters>
    <asp:Parameter Name="Caption" Type="String" />
    <asp:Parameter Name="Summary" Type="String" />
    <asp:Parameter Name="Text" Type="String" />
    <asp:Parameter Name="Name" Type="String" />
    <asp:Parameter Name="Email" Type="String" />
    <asp:Parameter Name="Phone" Type="String" />
    <asp:Parameter Name="PhoneHidden" Type="Boolean" />
    <asp:Parameter Name="Price" Type="Decimal" />
    <asp:Parameter Name="CategoryCodeID" Type="Byte" />
    <asp:Parameter Name="StateCodeID" Type="Byte" />
    <asp:Parameter Name="RegionCodeID" Type="Byte" />
    <asp:Parameter Name="StopDate" Type="DateTime" />
    <asp:Parameter Name="ModifiedBy" Type="Int32" />
    <asp:Parameter Name="CreatedOn" Type="DateTime" />
    <asp:Parameter Name="ModifiedOn" Type="DateTime" />
    <asp:Parameter DbType="Guid" Name="AdGUID" />
    <asp:Parameter Name="Original_AdID" Type="Int32" />
</UpdateParameters></asp:ObjectDataSource>
A: 

The data is updated as expected but no events seems to fire... the following redirect simply doesn't happen:

protected void FormView1_ItemUpdated(Object sender, FormViewCommandEventArgs e)
{
    Response.Redirect("www.stackoverflow.com");
}

The initial problem most likely resides from there, don't you think? The question is, how do I get the events to work as expected?

henrico
Does at least FormView1_ItemUpdating get called?
andrei m
No, changed to FormView1_ItemUpdating, but that doesn't work either... Could it have something to do with databinding on every postback?
henrico
In this case please check the page load to make sure that at least the page posts back when you click the button. One think that I find strange is that you have an InsertButton inside the EditTemplate of the FormView.
andrei m