当用户从中选择一行时,我希望 Formview 以插入模式开始,然后更改为编辑模式 Gridview 在同一页面中。
Formview具有内联属性: DefaultMode =“插入”
如何做到这一点,为什么这不起作用?
protected void GridView1_SelectedIndexChanged(object sender, System.EventArgs e)
{
FormView1.ChangeMode(FormViewMode.Edit);
}
EDIT1: FormView源代码
<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" />
<asp:LinkButton ID="UpdateButton" runat="server" CommandName="Update" Text="Update" CommandArgument='<%# Eval("AdID") %>' />
<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>
数据按预期更新,但似乎没有事件发生......以下重定向根本不会发生:
protected void FormView1_ItemUpdated(Object sender, FormViewCommandEventArgs e)
{
Response.Redirect("www.stackoverflow.com");
}
最初的问题很可能就是那里,你不觉得吗?问题是,如何使事件按预期工作?