无法更改 GridView_SelectedIndexChanged 上的 Formview 模式
我希望我的 Formview 以插入模式启动,然后在用户从 Gridview 中选择一行时更改为编辑模式在同一页面中。
Formview 具有内联属性:DefaultMode="Insert"
这是如何完成的以及为什么不起作用?
protected void GridView1_SelectedIndexChanged(object sender, System.EventArgs e)
{
FormView1.ChangeMode(FormViewMode.Edit);
}
编辑1: 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");
}
最初的问题很可能来自那里,您不认为吗?问题是,如何让事件按预期进行?
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" />
<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>
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论