在 ASP.NET 日历控件的 OnDayRender 事件期间添加 LinkBut​​tons [英] Add LinkButtons during OnDayRender event of ASP.NET Calendar Control

查看:26
本文介绍了在 ASP.NET 日历控件的 OnDayRender 事件期间添加 LinkBut​​tons的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我需要根据数据库中的数据动态地为 asp:calendar 控件的每个单元格添加一些链接按钮.我想知道这样做的最佳方法是什么,以便链接按钮将在回发时连接到它们的事件(据我所知,在 Day Render 事件上创建链接按钮并将它们添加到 LinkBut​​ton 事件之后会发生被解雇了).

So I need to add some link buttons to each cell of a asp:calendar control dynamically based on data in the database. I wondering what the best way to do this is so that the the link buttons will be wired up to their events on postbacks (as to my knowledge creating the link buttons on the Day Render event and adding them there will occur after the LinkButton events would have fired).

有没有人有好的方法来处理这个问题?

Does anyone have a nice way to handle this?

推荐答案

这是一个 hack,但它有效,你必须巧妙地处理事件命名......等等

This is a hack but it works, you will have to get crafty with the event naming...etc

标记:

<asp:Calendar id="calendar1" 
                OnDayRender="DayRender"
                runat="server">

<asp:LinkButton ID="LinkButton1" style="display:none;" runat="server" 
   onclick="LinkButton1_Click">LinkButton</asp:LinkButton>

代码隐藏:

protected void DayRender(Object source, DayRenderEventArgs e) 
{

    LinkButton lb = new LinkButton();
    lb.ID = "LinkButton1";
    //set all your props
     lb.Attributes.Add("href", 
        "javascript:__doPostBack('" + Calendar1.UniqueID + "$" + lb.ClientID +"','')");

    e.Cell.Controls.Add(lb);

}

protected void LinkButton1_Click(object sender, EventArgs e)
{
    //do something
}

这篇关于在 ASP.NET 日历控件的 OnDayRender 事件期间添加 LinkBut​​tons的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆