无法显示中的内容在表单视图中

发布于 2024-08-05 18:20:33 字数 3505 浏览 10 评论 0原文

由于 < 中的内容,我做错了什么?编辑项目模板>单击“编辑”按钮时不显示?

<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;
            }
        }
    }
}

What am I doing wrong since the content in the < EditItemTemplate > is not displayed when I click the Edit button?

<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>

Update

This is my code-behind:

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;
            }
        }
    }
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

自此以后,行同陌路 2024-08-12 18:20:33

如果记录为空,EditItemTemplate 也不会显示。换句话说,如果您有一个网格视图,您可以从中选择一条详细信息记录来提供给表单视图,并且它们没有所选网格项的详细信息,则该表单根本不会显示。我检查详细记录是否为空,如果是,我将表单视图或详细信息视图设置为“插入”模式。这样他们就可以输入新的记录。

The EditItemTemplate also won't show up if the record is empty. In other words, if you have a gridview that you select a detail record from that is feeding the formview, and their is no detail for the selected grid item, then the form won't show up at all. I check to see if the detail record is null, and if so, I set the formview or detailsview to "insert" mode. so they can enter a new record.

始终不够 2024-08-12 18:20:33

在您的函数 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

In your function fwHotelDetails_ModeChanging, add this:

fwHotelDetails.ChangeMode(FormViewMode.Edit)

i.e.

    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
萌无敌 2024-08-12 18:20:33

好的,您是否尝试过在 fwHotelDetails_ModeChanging 上放置断点,然后调试应用程序?单击编辑按钮时是否会命中断点。

至少这会告诉你你的问题出在哪里。那是 [1] 事件未正确连接或 [2] ChangeMode 出现问题。

我意识到这不是一个解决方案,但如果你告诉我断点是否命中,我可以进一步帮助你。

Ok have you tried putting a breakpoint on fwHotelDetails_ModeChanging and then debugging the App? Does the breakpoint get hit when you click the edit button.

At least this will tell you where your problem lies. That is [1] the events are not hooked up correctly or [2] there is something going wrong with ChangeMode.

I realise this isnt a solution but if you tell me whether the breakpoint hits i can help you further.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文