1

私の質問は簡単です。詳細ビューに入力されたレコードのカスタム保存および更新ボタンを作成するにはどうすればよいですか。与えられたものは使いたくありません。どうもありがとう。

4

2 に答える 2

1

いくつかのオプションがあります。1つはでOnItemCommandあり、独自のコマンドをロールします。 http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.detailsview.itemcommand.aspx

より簡単な方法は、OnItemInsertedandOnItemUpdatingイベントを使用することです。代わりに、必要に応じて挿入コマンドまたは更新コマンドを送信するだけで、より簡単なEventArgs http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.detailsview.iteminserting.aspx < http://msdnを使用できます。 .microsoft.com / en-us / library / system.web.ui.webcontrols.detailsview.itemupdating.aspx

これらのページから、基本的には、のボタンからコマンドをキャプチャしますDetailsView

ItemCommandを使用したカスタム「追加」コマンド

Sub CustomerDetailView_ItemCommand(ByVal sender As Object, ByVal e As DetailsViewCommandEventArgs)

    ' Use the CommandName property to determine which button
    ' was clicked. 
    If e.CommandName = "Add" Then
        ' Do your work here if Add Contact is clicked
    End If
End Sub

ItemInsertingを使用したより簡単な組み込みの挿入コマンド

Sub CustomerDetailView_ItemInserting((ByVal sender As Object, ByVal e As DetailsViewInsertEventArgs)
    ' Access the actual rows with
    Some variable1 = e.Values("CustomerID")
    Some variable2 = e.Values("CompanyName")
    Some variable3 = e.Values("City")

    ' Do something with them
End Sub

コードフロント

<asp:DetailsView ID="CustomerDetailView" 
    DataSourceID="DetailsViewSource"
    AutoGenerateRows="false" 
    DataKeyNames="CustomerID" 
    AllowPaging="true" 
    OnItemCommand="CustomerDetailView_ItemCommand"
    OnItemInserting="CustomerDetailView_ItemInserting"
    OnItemUpdating="CustomerDetailView_ItemUpdating"
    runat="server">
    <FieldHeaderStyle BackColor="Navy" ForeColor="White" />
    <Fields>
        <asp:BoundField DataField="CustomerID" HeaderText="Store ID" />
        <asp:BoundField DataField="CompanyName" HeaderText="Store Name" />
        <asp:BoundField DataField="City" HeaderText="City" />
        <asp:TemplateField HeaderText="Name">
            <InsertItemTemplate>
                <asp:Button ID="btAddContact" runat="server" Text="Add Contact" CommandName="Add" />
                            Or
                <asp:Button ID="btAddContact" runat="server" Text="Add Contact" CommandName="Insert" />
            </InsertItemTemplate>
            <EditItemTemplate>
                <asp:Button ID="btAddContact" runat="server" Text="Save Contact" CommandName="Update" />
            </EditItemTemplate>
        </asp:TemplateField>
    </Fields>
</asp:DetailsView>
于 2012-11-29T18:06:16.447 に答える
0

インターフェイスを実装する任意のボタンを使用できIButtonControlます。重要なのは、CommandNameを正しく設定することです。うまくいけば、これにより、ボタンを必要な方法でスタイリングする自由が得られます。

http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.button.commandname.aspx

関連するコマンド名のリストは、次の場所にあります。

http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.listview.itemcommand.aspx

<asp:ImageButton runat="server" ... CommandName="Save" />
<asp:LinkButton runat="server" ... CommandName="Update" />
于 2012-11-29T18:05:06.547 に答える