所以我需要根据数据库中的数据动态地为 asp:calendar 控件的每个单元格添加一些链接按钮.我想知道这样做的最佳方法是什么,以便链接按钮将在回发时连接到它们的事件(据我所知,在 Day Render 事件上创建链接按钮并将它们添加到 LinkButton 事件之后会发生被解雇了).
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 事件期间添加 LinkButtons的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!