Add LinkButtons during OnDayRender event of ASP.NET Calendar Control

后端 未结 1 1669
鱼传尺愫
鱼传尺愫 2021-01-03 13:10

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

相关标签:
1条回答
  • 2021-01-03 13:33

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

    Markup:

    <asp:Calendar id="calendar1" 
                    OnDayRender="DayRender"
                    runat="server">
    
    <asp:LinkButton ID="LinkButton1" style="display:none;" runat="server" 
       onclick="LinkButton1_Click">LinkButton</asp:LinkButton>
    

    Code-Behind:

    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
    }
    
    0 讨论(0)
提交回复
热议问题