0

私は現在、自分のプロジェクトの 1 つで asp:formview を使用しています。このように使用されます。

<asp:FormView ID="formViewGalleryEdit" runat="server" DefaultMode="Edit" 
            RenderOuterTable="False" DataKeyNames="GalleryID" 
            onitemupdating="formViewGalleryEdit_ItemUpdating">
            <EditItemTemplate>
                <div class="field-group">
                    <label for="textBoxVendorName">Gallery Heading:</label>
                    <div class="field">
                        <asp:TextBox runat="server" ID="textBoxGalleryHeading" Width="90%" 
                            Text='<%# Eval("GalleryHeading").ToString() %>' />
                    </div>
                </div>
                <div class="field-group">       
                    <label for="textBoxDescription">Gallery Description:</label>
                    <div class="field">
                        <asp:TextBox runat="server" ID="textBoxDescription" Text='<%# Eval("GalleryDescription") %>' 
                            Width="90%" Columns="50" 
                            Rows="7" TextMode="MultiLine" />
                    </div>      
                </div>
                <div class="field-group inlineField">   
                    <label for="myfile">Gallery Image:</label>
                    <div class="field">
                        <asp:FileUpload ID="imageFileUpload" runat="server" />
                    </div>  
                </div>
                <br />
                <div class="field-group inlineField">   
                    <div class="field">
                        <img src='/images/gallery/<%# Eval("GalleryImage") %>' alt='<%# Eval("GalleryImage") %>' />
                    </div>  
                </div>
                <div class="field-group">       
                    <label for="textBoxDescription">Gallery Button Text:</label>
                    <div class="field">
                        <asp:TextBox runat="server" ID="textBoxButtonText" Text='<%# Eval("GalleryButtonText") %>'
                            Width="90%" />
                    </div>      
                </div>
                <div class="field-group">       
                    <label for="textBoxDescription">Gallery Button URL:</label>
                    <div class="field">
                        <asp:TextBox runat="server" ID="textBoxGalleryUrl" Text='<%# Eval("GalleryButtonUrl") %>' Width="90%" />
                    </div>      
                </div>
                <br />
                <div class="field-group">       
                    <div class="actions">   
                        <asp:Button ID="buttonUpdate" runat="server" CausesValidation="True" CommandArgument='<%# Eval("GalleryId") %>' 
                            Width="60" CommandName="Update" Text="Update" />
                        <asp:Button ID="buttonCancel" runat="server" CausesValidation="False" Width="60"
                            CommandName="Cancel" Text="Cancel" />
                    </div> <!-- .actions -->
                </div>
            </EditItemTemplate>
        </asp:FormView>

さて、このファイルの背後にあるコードでは、次のように処理しています。

protected void formViewGalleryEdit_ItemUpdating(object sender, FormViewUpdateEventArgs e)
{
    try
    {
        string galleryId = e.CommandArgument.ToString();
        string galleryHeading = Server.HtmlEncode(((TextBox)formViewGalleryEdit.FindControl("textBoxGalleryHeading")).Text);
        string galleryDescription = ((TextBox)formViewGalleryEdit.FindControl("textBoxDescription")).Text;

        FileUpload control = (FileUpload)formViewGalleryEdit.FindControl("imageFileUpload");
        string galleryImage = control.FileName;
        string location = Server.MapPath("~/images/gallery/") + galleryImage;
        control.SaveAs(location);

        string galleryButtonText = ((TextBox)formViewGalleryEdit.FindControl("textBoxButtonText")).Text;
        string galleryUrl = ((TextBox)formViewGalleryEdit.FindControl("textBoxGalleryUrl")).Text;

        bool status = GalleryManager.UpdateGallery(galleryId, galleryHeading, galleryDescription, galleryImage,
                                                    galleryButtonText, galleryUrl);
        if (status)
        {
            literalSucess.Text = "Item Updated Successfully";
            panelScucess.Visible = true;
        }
    }
    catch (Exception ex)
    {
        literalError.Text = ex.Message;
        panelError.Visible = true;
    }

}

ブレークポイントも挿入しましたが、イベントが発生しません。私が間違っていることは何ですか?すべての回答に感謝します

4

3 に答える 3

2

すべてが 99% 正しいです。MSDN の例に示されているように、Buttonコントロールをコントロールに変更するだけで、準備完了です。LinkButton

<div class="actions">
    <asp:LinkButton ID="buttonUpdate" runat="server" CausesValidation="True" CommandArgument='<%# Eval("GalleryId") %>' 
                        Width="60" CommandName="Update" Text="Update" />
    <asp:LinkButton ID="buttonCancel" runat="server" CausesValidation="False" Width="60"
                        CommandName="Cancel" Text="Cancel" />
</div>
于 2012-07-19T18:35:41.047 に答える
0

これはばかげているように聞こえますが、次のコードを使用して問題を解決します。

if(!Page.IsPostBack())
{
    // code goes here
}
于 2012-07-21T09:40:31.110 に答える