Kamala Veni

Kamala Veni

  • NA
  • 65
  • 21.5k

How get the month data's selecting them ?

Mar 29 2016 6:00 AM
 I am having a sql table in that i have a data's  with date,month,year in saved format.if wanna a particular data's by selecting the month ,how get dat?
 
ex:
if i select march 2016
its show all details as per the month 
 
 
My code:
 
 
Month:
<asp:DropDownList ID="ddlMonth" runat="server" onchange = "PopulateDays()" CssClass="auto-style1" />
Year:
<asp:DropDownList ID="ddlYear" runat="server" onchange = "PopulateDays()" CssClass="auto-style1" />
<asp:Button ID="btnsub" runat="server" style="font-weight: 700; color: #000000; margin-left: 54px" Text="Submit" Width="70px" OnClick="btnsub_Click" />
<br />
<br />
 <asp:GridView ID="grv1" runat="server" style="margin-left: 3px; color: #000099; margin-top: 53px; font-weight: 700; " OnSelectedIndexChanged="grv1_SelectedIndexChanged" Height="149px" Width="396px"></asp:GridView>
<br />
 
 
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
if (this.SelectedDate == DateTime.MinValue)
{
this.PopulateYear();
this.PopulateMonth();
}
}
else
{
}
}
private int Month
{
get
{
return int.Parse(ddlMonth.SelectedItem.Value);
}
set
{
this.PopulateMonth();
ddlMonth.ClearSelection();
ddlMonth.Items.FindByValue(value.ToString()).Selected = true;
}
}
private int Year
{
get
{
return int.Parse(ddlYear.SelectedItem.Value);
}
set
{
this.PopulateYear();
ddlYear.ClearSelection();
ddlYear.Items.FindByValue(value.ToString()).Selected = true;
}
}
public DateTime SelectedDate
{
get
{
try
{
return DateTime.Parse(this.Month + "/" + this.Year);
}
catch
{
return DateTime.MinValue;
}
}
set
{
if (!value.Equals(DateTime.MinValue))
{
this.Year = value.Year;
this.Month = value.Month;
}
}
}
private void PopulateMonth()
{
ddlMonth.Items.Clear();
ListItem lt = new ListItem();
lt.Text = "MM";
lt.Value = "0";
ddlMonth.Items.Add(lt);
for (int i = 1; i <= 12; i++)
{
//ddlMonth.Items.Add(newSystem.Web.UI.WebControls.ListItem(DateTimeFormatInfo.CurrentInfo.GetMonthName(i), i.ToString()));
lt = new ListItem();
lt.Text = i.ToString();
// lt.Text = Convert.ToDateTime(i.ToString() + "/1/1900").ToString("MMMM");
lt.Value = i.ToString();
ddlMonth.Items.Add(lt);
}
ddlMonth.Items.FindByValue(DateTime.Now.Month.ToString()).Selected = true;
}
private void PopulateYear()
{
ddlYear.Items.Clear();
ListItem lt = new ListItem();
lt.Text = "YYYY";
lt.Value = "0";
ddlYear.Items.Add(lt);
for (int i = DateTime.Now.Year; i >= 1950; i--)
{
lt = new ListItem();
lt.Text = i.ToString();
lt.Value = i.ToString();
ddlYear.Items.Add(lt);
}
ddlYear.Items.FindByValue(DateTime.Now.Year.ToString()).Selected = true;
}
protected void btnsub_Click(object sender, EventArgs e)
{
string un = Session["Uname"].ToString();
// string mn = ddlMonth.Text;
//string que = "select [USER NAME],CPPUSR_NAME,HTSCNO,EDC,CONSUMERKV,SANCTIONMD,CPPQUANTUM_C,LOSS,CPPQUANTUM_G from TBL_CPPMASTER where EDC='" + t + "'";
string con = ConfigurationManager.ConnectionStrings["cppschConnectionString"].ConnectionString;
//string que = " select * from tbl_sch1 where SUBSTRING (DATE,5,1)='<% Response.Write(ddlMonth.Text); %>' AND SUBSTRING(DATE,7,4)='<% Response.Write(ddlYear.Text); %>'";
// string que = " select * from tbl_sch1 where [USER NAME]='" + un + "' AND (DATEPART(Month,[Date])) ='" + mn + "'";
//string que = " select * from tbl_sch1 where [USER NAME]='" + un + "'";// AND [Date]='";
// string que = " select * from tbl_sch1 where Date = '" + t + "' ";
// string que = " select * from tbl_sch1 where [Date]='30-03-2016'";
if (t == " ")
{
}
else
{
SqlDataAdapter da = new SqlDataAdapter(que, con);
DataTable dt = new DataTable();
da.Fill(dt);
grv1.DataSource = dt;
grv1.DataBind();
}
}
protected void grv1_SelectedIndexChanged(object sender, EventArgs e)
{
}
 

Answers (1)