如何为我的中继器制作通用页脚?

发布于 2024-10-19 10:47:57 字数 123 浏览 2 评论 0原文

我认为这个问题对于一些人来说可能显得非常愚蠢。但是我的 asp 应用程序中有多个中继器,我想知道如何使一些东西变得常见,例如页脚。

以及如何为我的中继器创建事件?就像页脚中引发自定义事件的按钮一样?谢谢各位的回复..

I Assume this question may be appear very dumb for ones.. But I have multiple repeaters in my asp application I wonder how I can make some things common like footer..

And How can I create events for my repeater? Like a button in the footer who raise an Custom event? Thanks for responses..

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

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

发布评论

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

评论(2

怂人 2024-10-26 10:47:57

您可以创建一个UserControl并将其放在页脚中。

对于事件,您需要将页脚连接到 ItemCommand 处理程序

<asp:repeater runat='server' id='myRepeater' onItemCommand='rptMyRepeater_ItemCommand'>
    <ItemTemplate>
        <!-- markup and controls -->
    </ItemTemplate>
    <footerTemplate>
        <asp:Button runat='server' id='btnOrf' Text='Click Me' CommandName='SomeAction' CommandArgument='100' />
    </FooterTemplate>
</asp:repeater>

然后在代码隐藏中定义一个处理转发器的 ItemCommand 事件的方法。您需要检查 ItemCommandEventArgs 参数以获取引发事件的按钮/控件的详细信息:

protected void rptMyRepeater_ItemCommand(object source, RepeaterCommandEventArgs e){
    if (e.CommandName == "SomeAction"){
        Response.Write ("The Command was " + e.CommandName + " and the value of the CommandArgument is: " + e.CommandArgument);

    }
}

您可以拥有任意数量的按钮,并具有不同的 CommandnameCommandArgument 例如“添加”、“保存”、“删除”、“更新”等。

通常您会绑定诸如数据项的数据库ID之类的内容(Users/Products/任何)到 CommandArgument,这样您就知道如何识别正在编辑/保存/删除/任何内容的对象。

<asp:Button runat='server' id='saveBtn' commandName='delete' CommandArgument='<%# Eval("UserId")%>' Text='Save' />

完整示例如下: http://msdn .microsoft.com/en-us/library/system.web.ui.webcontrols.repeater.itemcommand.aspx

MSDN 应该始终是您的第一个参考点;-)

You could create a UserControl and put that in your footers.

For events you need to hook your footer up to the ItemCommand handler.

<asp:repeater runat='server' id='myRepeater' onItemCommand='rptMyRepeater_ItemCommand'>
    <ItemTemplate>
        <!-- markup and controls -->
    </ItemTemplate>
    <footerTemplate>
        <asp:Button runat='server' id='btnOrf' Text='Click Me' CommandName='SomeAction' CommandArgument='100' />
    </FooterTemplate>
</asp:repeater>

Then in your codebehind you define a method which handles the repeater's ItemCommand event. You'll need to check the ItemCommandEventArgs parameter for details of the button/control that raised the event:

protected void rptMyRepeater_ItemCommand(object source, RepeaterCommandEventArgs e){
    if (e.CommandName == "SomeAction"){
        Response.Write ("The Command was " + e.CommandName + " and the value of the CommandArgument is: " + e.CommandArgument);

    }
}

You can have as many buttons as you like and with different Commandnames and CommandArguments e.g. 'Add', 'Save', 'Delete', 'Update' etc.

Usually you bind something like the database ID of the dataitem (Users/Products/whatever) to the CommandArgument so you know how to identify the object being edited/saved/deleted/whatever.

<asp:Button runat='server' id='saveBtn' commandName='delete' CommandArgument='<%# Eval("UserId")%>' Text='Save' />

Full Example here: http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.repeater.itemcommand.aspx

MSDN should always be your first point of reference ;-)

∞觅青森が 2024-10-26 10:47:57
  1. 我认为你需要创建一个表
    借助标题的结构,
    ItemTemplate 和页脚模板

    <前><代码><标题模板>
    <表>

    标题


    <项目模板>

    标题


    <页脚模板>

    标题


  2. 您需要在页脚中找到控件并分配事件。像这样:

    void Repeater_OnItemDataBound(对象源,DataGridItemEventArgs e)
    {
        if (e.Item.ItemType == ListItemType.Footer)
        {
            按钮全选 = (Button)e.Item.FindControl("全选");
        }
    }
    
  1. I think you need to create a TABLE
    structure with help of header,
    ItemTemplate, and footer templates

    <HeaderTemplate>
        <table>
            <Tr>
                <Td>Header</Td>
            </Tr>
    </HeaderTemplate>
    <ItemTemplate>
        <Tr>
            <Td>Header</Td>
        </Tr>
    </ItemTemplate>
    <FooterTemplate>
            <Tr>
                <Td>Header</Td>
            </Tr>
        </Table>
    </FooterTemplate>
    
  2. You need to find control in footer and assign events. Like this:

    void Repeater_OnItemDataBound(object source, DataGridItemEventArgs e)
    {
        if (e.Item.ItemType == ListItemType.Footer)
        {
            Button SelectAll = (Button)e.Item.FindControl("SelectAll");
        }
    }
    
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文