由于<中的内容,我做错了什么EditItemTemplate>单击“编辑”按钮时不显示?
<asp:FormView runat="server" id="fwHotelDetails" DataKeyNames="id" OnDataBound="fwHotelDetails_DataBound" OnModeChanging="fwHotelDetails_ModeChanging">
<ItemTemplate>
//display content here
<asp:LinkButton ID="EditButton" runat="server" CausesValidation="False" CommandName="Edit" Text="Edit" />
</ItemTemplate>
<EditItemTemplate>
This text should be displayed when I click the Edit button
<asp:LinkButton runat="server" ID="UpDateButton" CausesValidation="false" CommandName="Update" Text="Lagre" />
</EditItemTemplate>
</asp:FormView>
更新
这是我的代码隐藏:
namespace development.templates
{
public partial class HotelDetails : TemplatePage
{
static Hotel hotel;
protected DataRow drHotel;
DataTable dtCriteria;
DataTable dtHotel;
private HotelCriteria hotelCriteria;
protected void Page_Load(object sender, EventArgs e)
{
int hotelID = Convert.ToInt32(Request.QueryString["hotelid"].ToString());
if (!IsPostBack)
{
if (hotelID != 0)
{
// Create Hotel instance based on hoteID.
hotel = new Hotel(hotelID);
drHotel = hotel.hotelData.Rows[0];
dtHotel = hotel.getHotelsByCity(drHotel["city"].ToString());
// Hotel scrore is calculated from a score which is derived from certain criterias.
hotelCriteria = new HotelCriteria(hotelID);
dtCriteria = hotelCriteria.getHotelCriteria();
//Set datasource for hotel list in right sidebar.
hotelListByCity.DataSource = correctList(dtHotel, hotelID);
hotelListByCity.DataBind();
// Set datasource for current hotel
fwHotelDetails.DataSource = hotel.hotelData;
fwHotelDetails.DataBind();
}
}
}
protected void fwHotelDetails_DataBound(object sender, EventArgs e)
{
//Find the criteria list and set the datasource
Repeater rep = (Repeater)fwHotelDetails.FindControl("repCriteriaScore");
rep.DataSource = this.dtCriteria;
rep.DataBind();
// Controll is user is logged in. If logged in, then user may add, edit or delete hotel record.
System.Security.Principal.IPrincipal user = Context.User;
if ((user != null) && user.Identity.IsAuthenticated){
Panel panel = (Panel)fwHotelDetails.FindControl("administrationPanel");
panel.Visible = true;
}
}
protected void fwHotelDetails_ModeChanging(object sender, FormViewModeEventArgs e)
{
switch (e.NewMode)
{
case FormViewMode.Edit:
MessageLabel.Text = "Edit mode";
fwHotelDetails.ChangeMode(FormViewMode.Edit);
break;
case FormViewMode.ReadOnly:
MessageLabel.Text = "Read mode";
break;
case FormViewMode.Insert:
MessageLabel.Text = "Insert mode";
break;
}
}
}
}
答案 0 :(得分:1)
如果记录为空,EditItemTemplate也不会显示。换句话说,如果您有一个gridview,您从中选择了一个详细记录,并且它们不是所选网格项的详细信息,那么表单根本不会显示。我检查详细记录是否为空,如果是,我将formview或detailsview设置为“insert”模式。所以他们可以输入新的记录。
答案 1 :(得分:0)
在你的函数fwHotelDetails_ModeChanging中,添加:
fwHotelDetails.ChangeMode(FormViewMode.Edit)
即
Protected Sub fwHotelDetails_ModeChanging(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.FormViewModeEventArgs) Handles fwHotelDetails.ModeChanging
fwHotelDetails.ChangeMode(FormViewMode.Edit)
End Sub
答案 2 :(得分:0)
好的,您是否尝试在fwHotelDetails_ModeChanging上设置断点,然后调试应用程序?单击编辑按钮时是否会触发断点。
至少这会告诉你问题所在。那是[1]事件没有正确连接或[2] ChangeMode出现问题。
我意识到这不是一个解决方案,但如果你告诉我断点是否会命中,我可以帮助你。