ASP日历控件更改C#后面的背景颜色代码

时间:2016-07-21 11:49:08

标签: c# asp.net

如果日期在数据库表中可用,则应根据SQL表中的可用事件日期将日历背景颜色更改为红色。 以下是我的设计代码。

<asp:Calendar ID="Calendar1" runat="server" OnSelectionChanged="Calendar1_SelectionChanged">
</asp:Calendar>
Selected Date: <asp:Label ID="Label1" runat="server" ></asp:Label>

 <br />
 <br />

  <asp:GridView ID="gv_Regdetails" runat="server" AllowSorting="True"
                AlternatingRowStyle-CssClass="alt" AutoGenerateColumns="False" CssClass="mGrid"
                Width="900px" PageSize="50">
                <RowStyle HorizontalAlign="Center" />
                <AlternatingRowStyle CssClass="alt" />
                <Columns>
                    <asp:TemplateField HeaderText="Sno">
                        <ItemTemplate>
                            <%# Container.DataItemIndex + 1 %>
                        </ItemTemplate>
                        <HeaderStyle HorizontalAlign="Center" Width="30px" />
                        <ItemStyle CssClass="th" HorizontalAlign="Center" Width="30px" />
                    </asp:TemplateField>
                    <asp:BoundField DataField="EventName" HeaderText="EventName">
                        <ItemStyle CssClass="th" HorizontalAlign="Left" Width="30px" />
                        <HeaderStyle HorizontalAlign="Left" Width="30px" Height="25px" />
                    </asp:BoundField>
                    <asp:BoundField DataField="Title" HeaderText="Title">
                        <ItemStyle CssClass="th" HorizontalAlign="Left" Width="30px" />
                        <HeaderStyle HorizontalAlign="Left" Width="30px" Height="25px" />
                    </asp:BoundField>

                    <asp:BoundField DataField="Description" HeaderText="Description">
                        <ItemStyle CssClass="th" HorizontalAlign="Left" Width="30px" />
                        <HeaderStyle HorizontalAlign="Left" Width="30px" Height="25px" />
                    </asp:BoundField>

                </Columns>
                <EmptyDataTemplate>
                    <center>
                                    <asp:Label ID="Label12" runat="server" Text="No Data avaliable for selected dates"
                                        ForeColor="Red"></asp:Label></center>
                </EmptyDataTemplate>
            </asp:GridView>

下面是我的c#代码,我在Calendar1_DayRender方法中编写逻辑。

protected void Calendar1_SelectionChanged(object sender, EventArgs e)
{        
    Label1.Text = Calendar1.SelectedDate.ToShortDateString();
    bo.Para1 = Label1.Text;
    DataTable dt = new DataTable();
    dt = bl.Get_detailsbydate(bo);
    gv_Regdetails.DataSource = dt;
    gv_Regdetails.DataBind();
}
protected void Calendar1_DayRender(object sender, DayRenderEventArgs e)
{
    DataTable dt = new DataTable();
    dt = bl.Get_detailsbydate(bo);
    string dates = dt.Rows[0]["EventDate"].ToString();

 //   if (e.Day.Date == dates)
//    { 
 //           e.Day.IsSelectable = false;
 //           e.Cell.ForeColor = System.Drawing.Color.Red;
//    }


}

1 个答案:

答案 0 :(得分:0)

ArrayList<IJavaElement> links