USE [dbFiles]
GO
/****** Object: Table [dbo].[tb_data] Script Date: 06-Sep-17 2:30:06 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[tb_data](
[id] [int] IDENTITY(1,1) NOT NULL,
[amount] [int] NULL,
[tb_date] [date] NULL,
CONSTRAINT [PK_tb_data] PRIMARY KEY CLUSTERED
(
[id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
SET IDENTITY_INSERT [dbo].[tb_data] ON
GO
INSERT [dbo].[tb_data] ([id], [amount], [tb_date]) VALUES (1, 100, CAST(0x4F3D0B00 AS Date))
GO
INSERT [dbo].[tb_data] ([id], [amount], [tb_date]) VALUES (2, 1000, CAST(0x503D0B00 AS Date))
GO
INSERT [dbo].[tb_data] ([id], [amount], [tb_date]) VALUES (3, 200, CAST(0x7B3C0B00 AS Date))
GO
INSERT [dbo].[tb_data] ([id], [amount], [tb_date]) VALUES (4, 2000, CAST(0x7C3C0B00 AS Date))
GO
SET IDENTITY_INSERT [dbo].[tb_data] OFF
GO
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;
using System.Data.SqlClient;
using System.Configuration;
using System.Data;
using System.Globalization;
using System.Text;
public partial class Default2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
if (DropDownList1.SelectedValue != "Select" && DropDownList2.SelectedValue != "Select")
{
int year = Convert.ToInt32(DropDownList2.SelectedValue.ToString());
int month = Convert.ToInt32(DropDownList1.SelectedValue.ToString());
List<DateTime> daysOfMonth = Enumerable.Range(1, DateTime.DaysInMonth(year, month)) // Days: 1, 2 ... 31 etc.
.Select(day => new DateTime(year, month, day)) // Map each day to a date
.ToList();
StringBuilder sb = new StringBuilder();
StringBuilder sb1 = new StringBuilder();
string strConnString = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
using (SqlConnection con = new SqlConnection(strConnString))
{
using (SqlCommand cmd = new SqlCommand())
{
foreach (DateTime d in daysOfMonth)
{
sb.Append("<th>");
sb.Append(d.ToString("dd"));
sb.Append("</th>");
//cmd.CommandText = "select * from tb_data";
//cmd.Connection = con;
//con.Open();
//SqlDataReader dr = cmd.ExecuteReader();
//while (dr.Read())
//{
// string seldate = d.ToString("dd/M/yyyy");
// string date = DateTime.Parse(dr[2].ToString()).ToString("dd/M/yyyy");
// if (seldate == date)
// {
// sb1.Append("<tr>");
// sb1.Append(dr[1].ToString());
// sb1.Append("</tr>");
// }
//}
//dr.Close();
con.Close();
}
Literal1.Text = sb.ToString();
}
}
}
}
}
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" %>
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
Select Month:
<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="true" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged">
<asp:ListItem>Select</asp:ListItem>
<asp:ListItem Value="1">January</asp:ListItem>
<asp:ListItem Value="2">February</asp:ListItem>
<asp:ListItem Value="3">March</asp:ListItem>
<asp:ListItem Value="4">April</asp:ListItem>
<asp:ListItem Value="5">May</asp:ListItem>
<asp:ListItem Value="6">June</asp:ListItem>
<asp:ListItem Value="7">July</asp:ListItem>
<asp:ListItem Value="8">August</asp:ListItem>
<asp:ListItem Value="9">September</asp:ListItem>
<asp:ListItem Value="10">October</asp:ListItem>
<asp:ListItem Value="11">November</asp:ListItem>
<asp:ListItem Value="12">December</asp:ListItem>
</asp:DropDownList>
Select Year
<asp:DropDownList ID="DropDownList2" runat="server" AutoPostBack="true" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged">
<asp:ListItem>Select</asp:ListItem>
<asp:ListItem>2010</asp:ListItem>
<asp:ListItem>2011</asp:ListItem>
<asp:ListItem>2012</asp:ListItem>
<asp:ListItem>2013</asp:ListItem>
<asp:ListItem>2014</asp:ListItem>
<asp:ListItem>2015</asp:ListItem>
<asp:ListItem>2016</asp:ListItem>
<asp:ListItem>2017</asp:ListItem>
<asp:ListItem>2018</asp:ListItem>
</asp:DropDownList>
<table width="100%">
<asp:Literal ID="Literal1" runat="server"></asp:Literal>
<asp:Literal ID="Literal2" runat="server"></asp:Literal>
</table>
</div>
</form>
</body>
</html>
i wont to show pivort chart of selected month and year.
and selected month and year in response to show all date in row if that date match with data base table it will show amount on that date below