I explain from example of what I face issue about dropdownlist SelectedIndexChanged event : I have two dropdownlist and both have own SelectedIndexChanged event but issue is that when I call first dropdownlist SelectedIndexChanged that time it call perfect but when i call second dropdownlist SelectedIndexChanged is call own as well that first dropdownlist SelectedIndexChanged and it show first dropdownlist SelectedIndexChanged event data

First Dropdownlist 

<asp:DropDownList ID="DDReportType" runat="server" CssClass="dropdown" style="width:100%;" AutoPostBack="true" OnSelectedIndexChanged="DDReportType_SelectedIndexChanged">
                    <asp:ListItem>Week</asp:ListItem>
                     <asp:ListItem>Semimonthly</asp:ListItem>
                     <asp:ListItem>Month</asp:ListItem>
                     <asp:ListItem>Quarter</asp:ListItem>
                     <asp:ListItem>Year</asp:ListItem>
                     <asp:ListItem>Custom</asp:ListItem>                   
                </asp:DropDownList>

    second dropdownlist
<asp:DropDownList ID="DDdownloadreport" runat="server" CssClass="dropdown"  AutoPostBack="true" OnSelectedIndexChanged="DDdownloadreport_SelectedIndexChanged">
                            <asp:ListItem>Export</asp:ListItem>
                            <asp:ListItem>Excel</asp:ListItem>
                            <asp:ListItem>CSV</asp:ListItem>                      
                    </asp:DropDownList></div>

both codebind



protected void DDReportType_SelectedIndexChanged(object sender, EventArgs e)
    {
        try
        {
            if(DDReportType.SelectedValue.ToString()=="Week")
            {
                TimeSheetWeekNumber.Value = "";
                lblThisWeek.Text = "This Week:";
                BindDataClientWise();
                BindDataProjectWise();
                BindDataTaskWise();
                BindDataStaffWise();
                DateLabelDisplay();

            }
            else if (DDReportType.SelectedValue.ToString() == "Month")
            {
                TimeSheetMonthNumber.Value = "";
                TimeSheetYearNumbrer.Value = "";
                lblThisWeek.Text = "This Month:";
                BindDataClientWise();
                BindDataProjectWise();
                BindDataTaskWise();
                BindDataStaffWise();
                DateLabelDisplay();
            }
            else if (DDReportType.SelectedValue.ToString() == "Quarter")
            {
                TimeSheetQuarterNumber.Value = "";
                TimeSheetYearNumbrer.Value = "";
                lblThisWeek.Text = "This Quarter:";
                BindDataClientWise();
                BindDataProjectWise();
                BindDataTaskWise();
                BindDataStaffWise();
                DateLabelDisplay();
            }
            else if (DDReportType.SelectedValue.ToString() == "Year")
            {
                TimeSheetYearNumbrer.Value = "";
                lblThisWeek.Text = "This Year:";
                BindDataClientWise();
                BindDataProjectWise();
                BindDataTaskWise();
                BindDataStaffWise();
                DateLabelDisplay();
            }


        }
        catch (Exception ex)
        {
            ex.Message.ToString();

        }
    }
    public DataTable DisplayInExcel()
    {

        try
        {
            dt = new DataTable();
            using (SqlConnection con = new SqlConnection(str))
            {
                con.Open();
                SqlCommand cmd = new SqlCommand("ReportPageDisplayToExcel", con);
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.CommandText = "ReportPageDisplayToExcel";
                cmd.Parameters.AddWithValue("@ReportType", DDReportType.SelectedValue.ToString());
                cmd.Parameters.AddWithValue("@RoleId", Convert.ToInt32(Session["RoleId"]));
                cmd.Parameters.AddWithValue("@EmployeeId", Session["cname"].ToString());


                SqlDataAdapter da = new SqlDataAdapter(cmd);
                da.Fill(dt);
                con.Close();

            }



        }
        catch (Exception ex)
        {
            ex.Message.ToString();
        }
        return dt;
    }
    protected void DDdownloadreport_SelectedIndexChanged(object sender, EventArgs e)
    {
        try
        {
            if (DDdownloadreport.SelectedValue == "Excel")
            {
                Response.ClearContent();
                Response.Buffer = true;
                Response.AddHeader("content-disposition", string.Format("attachment; filename={0}", "Report.xls"));
                Response.ContentType = "application/ms-excel";
                DataTable dt = DisplayInExcel();
                string str = string.Empty;
                foreach (DataColumn dtcol in dt.Columns)
                {
                    Response.Write(str + dtcol.ColumnName);
                    str = "\t";
                }
                Response.Write("\n");
                foreach (DataRow dr in dt.Rows)
                {
                    str = "";
                    for (int j = 0; j < dt.Columns.Count; j++)
                    {
                        Response.Write(str + Convert.ToString(dr[j]));
                        str = "\t";
                    }
                    Response.Write("\n");
                }
                Response.End();
            }


        }
        catch (Exception ex)
        {
            ex.Message.ToString();
        }
    }

Related posts

Recent Viewed