Wrox Programmer Forums
| Search | Today's Posts | Mark Forums Read
ASP.NET 2.0 Professional If you are an experienced ASP.NET programmer, this is the forum for your 2.0 questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Professional section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old August 13th, 2008, 11:30 PM
Authorized User
 
Join Date: Oct 2007
Location: , , .
Posts: 20
Thanks: 0
Thanked 0 Times in 0 Posts
Default Dropdownlist getting deleted.

Hello All ,

I am writing this code to generate dropdownlist for a month and year and then 31 checkboxes for each day of the month. There are 6 rows like this. After that i wanted that as soon as a user selects month and year all the checkboxes for sundays of that particular month should get disabled and replaced by "s" for that i had added label also and it worked but it is giving strange behavious when the first day of a month is Sunday for example for month = 5 and year = 2011 it displays right for that row but as soon as i select another month in the next row ddl of first row month gets deleted and moreover checkbox of 1 which was disabled also get visible.

Please can any one help me out to resolve this issue ? thanks in advance. Below is the code which i am using.



using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Collections;

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
          for (int i = 0; i <= 6; i++)
            {
                TableRow t1 = new TableRow();
                tbltemp.Rows.Add(t1);
                for (int j = 0; j <= 31; j++)
                {
                    TableCell tc = new TableCell();
                    if (i == 0 && j == 0)
                    {
                        tc.Text = "Month / Year";
                        t1.Cells.Add(tc);
                    }
                    else if (i == 0)
                    {
                        tc.Text = Convert.ToString(j);
                        t1.Cells.Add(tc);
                    }

                    else if (j != 0)
                    {
                        CheckBox chk = new CheckBox();
                        chk.ID = "chk" + i + j;
                        chk.Enabled = true;
                        Label lbl = new Label();
                        lbl.ID = "lbl" + i + j;
                        lbl.Text = "";
                        lbl.Visible = false;
                        tc.Controls.Add(chk);
                        tc.Controls.Add(lbl);
                        t1.Cells.Add(tc);

                    }
                    if (i > 0 && j == 0)
                    {

                        DropDownList ddl1 = new DropDownList();
                        ddl1.SelectedIndexChanged += new EventHandler(ddl1_SelectedIndexChanged);
                        ddl1.AutoPostBack = true;
                        ddl1.ID = "ddlMonth" + i + "1";

                        ddl1.Items.Add("Select");
                        for (int k = 1; k <= 12; k++)
                            ddl1.Items.Add(k.ToString());
                        tc.Controls.Add(ddl1);
                        t1.Cells.Add(tc);

                        DropDownList ddl2 = new DropDownList();
                        ddl2.SelectedIndexChanged += new EventHandler(ddl2_SelectedIndexChanged);

                        ddl2.AutoPostBack = true;

                        ddl2.ID = "ddlYear" + i + "2";
                        int cyear = DateTime.Now.Year; ;
                        ddl2.Items.Add("Select");
                        for (int x = cyear; x <= cyear + 10; x++)
                            ddl2.Items.Add(x.ToString());
                        tc.Controls.Add(ddl2);
                        t1.Cells.Add(tc);


                    }

                }
            }


            protected void ddl2_SelectedIndexChanged(object sender, EventArgs e)
    {

        DropDownList ddlY = (DropDownList)sender;
        string ddlname = ddlY.ID.ToString();
        string abc = ddlname.Substring(7, 1);
        int a = Convert.ToInt32(abc);

        string month = "ddlMonth" + a + "1";
        DropDownList ddlM = (DropDownList)tbltemp.FindControl(month);
        if (ddlM.SelectedValue.ToString() != "Select" && ddlY.SelectedValue.ToString() != "Select")
        {

            int intMonth = Convert.ToInt32(ddlM.SelectedValue);
            int intYear = Convert.ToInt32(ddlY.SelectedValue);

            MarkSundays(intMonth, intYear, a);
                   }

    }


    protected void ddl1_SelectedIndexChanged(object sender, EventArgs e)
    {
        DropDownList ddlM = (DropDownList)sender;
        string ddlname = ddlM.ID.ToString();
        string abc = ddlname.Substring(8, 1);
        int a = Convert.ToInt32(abc);

        string year = "ddlYear" + a + "2";
        DropDownList ddlY = (DropDownList)tbltemp.FindControl(year);
        if (ddlM.SelectedValue.ToString() != "Select" && ddlY.SelectedValue.ToString() != "Select")
        {

            int intMonth = Convert.ToInt32(ddlM.SelectedValue);
            int intYear = Convert.ToInt32(ddlY.SelectedValue);
            MarkSundays(intMonth, intYear, a);
                   }

    }

    public void MarkSundays(int Month, int Year,int a)
    {
        int Month1 = Month;
        int Year1 = Year;
        int a1 = a;
        Label l1 = new Label();
        l1.Text = "S";
        int intDaysThisMonth = DateTime.DaysInMonth(Year1, Month1);
        DateTime oBeginnngOfThisMonth = new DateTime(Year1, Month1, 1);

            for (int z = 0; z < intDaysThisMonth ; z++)
            {

                if (oBeginnngOfThisMonth.AddDays(z).DayOfWeek == DayOfWeek.Sunday)
                {
                    int x =z + 1;
                    string c = "chk" + a1 + x;
                    string l = "lbl" + a1 + x;
                    CheckBox chktemp = (CheckBox)tbltemp.FindControl(c);
                      chktemp.Visible = false;
                    //chktemp.Enabled = false;
                   // chktemp.Text = "S";


                }

            }


    }
 }




Similar Threads
Thread Thread Starter Forum Replies Last Post
mapped folder is deleted @shish ASP.NET 2.0 Professional 1 July 7th, 2008 06:18 AM
Subscriptions deleted? Gert Forum and Wrox.com Feedback 3 December 2nd, 2004 11:18 AM
Deleted Printers Table Teqlump Access VBA 1 September 10th, 2004 05:50 PM
deleted bcmaverik VB.NET 2002/2003 Basics 0 March 13th, 2004 06:25 AM
#Deleted jeff_M Access 6 August 29th, 2003 01:27 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.