Click here to Skip to main content
15,897,226 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
if i want like this.. how to do in vb.net with asp.net

Dropdownlist: aug-2013// month-year

gridview:

Days              dates 
sunday(day name) 1-aug-2013 (dd-mmm-yyyy) 
monday           2-aug-2013
tusday           3-aug-2013
wedday           4-aug-2013
thuday           5-aug-2013
friday           6-aug-2013
satday           7-aug-2013
.................................

so on            31-aug-2013
i want like this format plz help me:
Posted
Updated 19-Aug-13 6:19am
v5
Comments
Sergey Alexandrovich Kryukov 18-Aug-13 3:48am    
Despite of so many question marks, this is not a question at all. Help with what? Where do you see your problem?
—SA
priyanshbhaliya 18-Aug-13 4:32am    
i have gridview and i want to display days by row wish in gridview when i select month in dropdownlist
Sergey Alexandrovich Kryukov 18-Aug-13 11:39am    
First, http://whathaveyoutried.com? Any code sample? What did you want to get? What did you observe instead? Why do you think this is wrong? What is your question about this problem?
—SA
Sergey Alexandrovich Kryukov 18-Aug-13 11:33am    
"Don't know" about what? About what to do with non-questions? Usually, not answering to them.
—SA
priyanshbhaliya 19-Aug-13 4:12am    
can u get what is i need ? Sergey Alexandrovich Kryukov sir

C#
using System;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Collections.Generic;

public partial class _Default : System.Web.UI.Page
{
    class myClass
    {
        string _date;
        string _dayOfWeek;

        public string date
        {
            get { return _date; }
            set { _date = value; }
        }

        public string dayOfWeek
        {
            get { return _dayOfWeek; }
            set { _dayOfWeek = value; }
        }
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            ddlYear_DataBing(2012);
            ddlMonth_DataBing();
            gvDays_DataBing();
        }
    }

    private void ddlYear_DataBing(int startYear)
    {
        int currentYear = Convert.ToInt32(DateTime.Now.Year.ToString());

        for (int i = startYear; i <= currentYear; i++)
        {
            ListItem item = new ListItem(string.Format("{0}", i));

            ddlYear.Items.Add(item);
        }
    }

    private void ddlMonth_DataBing()
    {
        ListItem monthItem = new ListItem("jan", "1");
        ddlMonth.Items.Add(monthItem);

        monthItem = new ListItem("feb", "2");
        ddlMonth.Items.Add(monthItem);

        monthItem = new ListItem("mar", "3");
        ddlMonth.Items.Add(monthItem);

        monthItem = new ListItem("apr", "4");
        ddlMonth.Items.Add(monthItem);

        monthItem = new ListItem("may", "5");
        ddlMonth.Items.Add(monthItem);

        monthItem = new ListItem("jun", "6");
        ddlMonth.Items.Add(monthItem);

        monthItem = new ListItem("jul", "7");
        ddlMonth.Items.Add(monthItem);

        monthItem = new ListItem("aug", "8");
        ddlMonth.Items.Add(monthItem);

        monthItem = new ListItem("sep", "9");
        ddlMonth.Items.Add(monthItem);

        monthItem = new ListItem("oct", "10");
        ddlMonth.Items.Add(monthItem);

        monthItem = new ListItem("nov", "11");
        ddlMonth.Items.Add(monthItem);

        monthItem = new ListItem("dec", "12");
        ddlMonth.Items.Add(monthItem);
    }

    private void gvDays_DataBing()
    {
        int month = Convert.ToInt32(ddlMonth.SelectedValue);

        List<myClass> myList = new List<myClass>();

        if (month == 1 || month == 3 || month == 5 || month == 7 || month == 8 || month == 10 || month == 12)
        {
            for (int i = 1; i <= 31; i++)
            {
                myClass item = new myClass();
                item.date = string.Format("{0}-{1}-{2}", i.ToString(), ddlMonth.SelectedItem.Text, ddlYear.SelectedValue);
                DateTime dateValue = new DateTime(Convert.ToInt32(ddlYear.SelectedValue), Convert.ToInt32(ddlMonth.SelectedValue), i);
                item.dayOfWeek = dateValue.ToString("ddddddddd");

                myList.Add(item);
            }
        }
        else
            if (month == 4 || month == 6 || month == 9 || month == 11)
            {
                for (int i = 1; i <= 30; i++)
                {
                    myClass item = new myClass();
                    item.date = string.Format("{0}-{1}-{2}", i.ToString(), ddlMonth.SelectedItem.Text, ddlYear.SelectedValue);
                    DateTime dateValue = new DateTime(Convert.ToInt32(ddlYear.SelectedValue), Convert.ToInt32(ddlMonth.SelectedValue), i);
                    item.dayOfWeek = dateValue.ToString("ddddddddd");

                    myList.Add(item);
                }
            }
            else
            {
                for (int i = 1; i <= 28; i++)
                {
                    myClass item = new myClass();
                    item.date = string.Format("{0}-{1}-{2}", i.ToString(), ddlMonth.SelectedItem.Text, ddlYear.SelectedValue);
                    DateTime dateValue = new DateTime(Convert.ToInt32(ddlYear.SelectedValue), Convert.ToInt32(ddlMonth.SelectedValue), i);
                    item.dayOfWeek = dateValue.ToString("ddddddddd");

                    myList.Add(item);
                }
            }

        gvDays.DataSource = myList;
        gvDays.DataBind();
    }



    protected void ddlMonth_SelectedIndexChanged(object sender, EventArgs e)
    {
        gvDays_DataBing();
    }

    protected void ddlYear_SelectedIndexChanged(object sender, EventArgs e)
    {
        gvDays_DataBing();
    }
}
 
Share this answer
 
v2
Comments
priyanshbhaliya 20-Aug-13 2:59am    
i get error in this line:
DateTime dateValue = new DateTime(Convert.ToInt32(ddlYear.SelectedValue), Convert.ToInt32(ddlYear.SelectedValue), i);

Year, Month, and Day parameters describe an un-representable DateTime
Neema Derakhshan 20-Aug-13 6:44am    
check the code again !
you have 2 ddlYear.SelectedValue in your line,but in the code is ddlYear.SelectedValue and then ddlMonth.SelectedValue !
priyanshbhaliya 20-Aug-13 7:45am    
thnks a lot
Neema Derakhshan 20-Aug-13 14:45pm    
your welcome dude
i'm sure this not the best solution,but i hope it help you
priyanshbhaliya 22-Aug-13 4:28am    
hey.. ur solution is best..ok
C#
using System;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Collections.Generic;

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            ddlMonth_DataBing(2012);
            gvDays_DataBing();
        }
    }

    private void ddlMonth_DataBing(int startYear)
    {
        int currentYear = Convert.ToInt32(DateTime.Now.Year.ToString());

        for (int i = startYear; i <= currentYear; i++)
        {
            ListItem item = new ListItem(string.Format("{0}", i));

            ddlYear.Items.Add(item);
        }

        for (int j = 1; j <= 12; j++)
        {
            ListItem item = new ListItem(string.Format("{0}", j));

            ddlMonth.Items.Add(item);
        }
    }

    private void gvDays_DataBing()
    {
        int month = Convert.ToInt32(ddlMonth.SelectedValue);

        List<string> daysList = new List<string>();

        if (month < 7)
        {
            for (int i = 1; i <= 31; i++)
            {
                daysList.Add(string.Format("{0}/{1}/{2}", i.ToString(), ddlMonth.SelectedValue, ddlYear.SelectedValue));
            }
        }
        else
        {
            for (int i = 1; i <= 30; i++)
            {
                daysList.Add(string.Format("{0}/{1}/{2}", i.ToString(), ddlMonth.SelectedValue, ddlYear.SelectedValue));
            }
        }

        gvDays.DataSource = daysList;
        gvDays.DataBind();
    }

    protected void ddlMonth_SelectedIndexChanged(object sender, EventArgs e)
    {
        gvDays_DataBing();
    }

    protected void ddlYear_SelectedIndexChanged(object sender, EventArgs e)
    {
        gvDays_DataBing();
    }
}
 
Share this answer
 
v2
Comments
priyanshbhaliya 18-Aug-13 6:54am    
get error in "string.Format({0}/month/year)"
Sergey Alexandrovich Kryukov 18-Aug-13 11:37am    
What is that, a mix of VB.NET, C# and HTML, or something else? Apparently, it could not even compile.
If you are not confident in writing code on the fly, you should always test it. Not answering at all is less harm then answering this way.
—SA
Neema Derakhshan 19-Aug-13 0:17am    
ok,sorry guys,my fault
but the new solution is c# and tested
priyanshbhaliya 19-Aug-13 7:22am    
reply...plz
priyanshbhaliya 19-Aug-13 10:52am    
some one give ans....

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900