Click here to Skip to main content
15,887,135 members
Home / Discussions / ASP.NET
   

ASP.NET

 
GeneralRe: FromUri Method - API Pin
Richard Deeming6-Dec-13 1:33
mveRichard Deeming6-Dec-13 1:33 
QuestionSuggest me a website in asp dotnet Pin
Member 1041107418-Nov-13 23:15
Member 1041107418-Nov-13 23:15 
AnswerRe: Suggest me a websit in asp dotnet Pin
Chris Quinn18-Nov-13 23:22
Chris Quinn18-Nov-13 23:22 
AnswerRe: Suggest me a website in asp dotnet Pin
Dineshshp18-Nov-13 23:39
professionalDineshshp18-Nov-13 23:39 
AnswerRe: Suggest me a website in asp dotnet Pin
Chris Quinn19-Nov-13 0:42
Chris Quinn19-Nov-13 0:42 
AnswerRe: Suggest me a website in asp dotnet Pin
thatraja19-Nov-13 1:09
professionalthatraja19-Nov-13 1:09 
AnswerRe: Suggest me a website in asp dotnet Pin
Abhinav S19-Nov-13 16:56
Abhinav S19-Nov-13 16:56 
QuestionDropdown list based on another dropdown list. Pin
Member 1040983818-Nov-13 10:20
Member 1040983818-Nov-13 10:20 
I have a dropdown list (dlStage) which uses the selected value of another dropdown list (dlJobName) to populate the values. I have both of the ddls set with Autopostback = true but the list dlStage is not populating. I am including the code here for reference. My ultimate goal is to have the user select a value from the dlJobName and then select a value from the dlStage and then the gridview would populate. I had this working when there was basically one stage per JobName. Now there are multiple Stages and the stages are not consistent across jobnames. For example, JobName 123 could have Stage = Release. While 124 would have Stage Final and First. If the update is not done properly, the gridview does not show results or I get an error that the stage does not exist.
C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Web.Security;
using System.Configuration;

namespace AnnoTracker
{
    public partial class WebForm1 : System.Web.UI.Page
    {
        public static class MyVariables
        {
            public static int PI = 0;
            public static string JN = "";
            public static string ST = "";
            public static string AT = "";
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (MyVariables.AT == "")
                {
                    dlAnnoType.DataBind();
                    dlAnnoType.SelectedValue = "Agency Error";
                }
                if (MyVariables.AT != "")
                {
                    dlAnnoType.DataBind();
                    dlAnnoType.SelectedValue = MyVariables.AT;
                }
                if (MyVariables.JN == "")
                {
                    dlJobName.DataBind();
                    dlJobName.SelectedIndex = 0;
                }
                if (MyVariables.JN != "")
                {
                    dlJobName.DataBind();
                    dlJobName.SelectedValue = MyVariables.JN;
                }
                if (MyVariables.ST == "")
                {
                    dlStage.DataBind();
                    dlStage.SelectedIndex = 0;
                }
                //dlStage.SelectedIndex = 0;
                dlStage.DataBind();

                BindData();

                if (MyVariables.PI == 0)
                {
                    gvSummary.DataBind();
                    gvSummary.PageIndex = 0;
                }
                if (MyVariables.PI != 0)
                {
                    gvSummary.DataBind();
                    gvSummary.PageIndex = MyVariables.PI;
                }
            }
        }

        protected void EditSummary(object sender, GridViewEditEventArgs e)
        {
            gvSummary.EditIndex = e.NewEditIndex;
            string _custName = gvSummary.DataKeys[e.NewEditIndex].Value.ToString();
            BindData();
        }

        protected void CancelEdit(object sender, GridViewCancelEditEventArgs e)
        {
            gvSummary.EditIndex = -1;
            BindData();
        }

        protected void gvSummary_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            gvSummary.PageIndex = e.NewPageIndex;
            MyVariables.PI = e.NewPageIndex;
            BindData();
        }


        protected void RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow && gvSummary.EditIndex == e.Row.RowIndex)
            {

                DropDownList dlBU = (DropDownList)e.Row.FindControl("dlBU");

                string _custName = gvSummary.DataKeys[e.Row.RowIndex].Values[1].ToString();
                string BUquery = "select distinct Unit from vw_BU where Business='" + _custName + "'";
                SqlCommand BUcmd = new SqlCommand(BUquery);
                dlBU.DataSource = GetData(BUcmd);
                dlBU.DataTextField = "Unit";
                dlBU.DataValueField = "Unit";
                dlBU.DataBind();
                dlBU.Items.FindByValue((e.Row.FindControl("lblBU") as Label).Text).Selected = true;

                DropDownList dlPA = (DropDownList)e.Row.FindControl("dlPA");

                string _PAcustName = gvSummary.DataKeys[e.Row.RowIndex].Values[1].ToString();
                string PAquery = "select PA from PA where Business='" + _PAcustName + "' order by PA";
                SqlCommand PAcmd = new SqlCommand(PAquery);
                dlPA.DataSource = GetData(PAcmd);
                dlPA.DataTextField = "PA";
                dlPA.DataValueField = "PA";
                dlPA.DataBind();
                dlPA.Items.FindByValue((e.Row.FindControl("lblPA") as Label).Text).Selected = true;

                DropDownList dlET = (DropDownList)e.Row.FindControl("dlET");

                string ETquery = "select distinct ErrorType from ErrorType order by ErrorType";
                SqlCommand ETcmd = new SqlCommand(ETquery);
                dlET.DataSource = GetData(ETcmd);
                dlET.DataTextField = "ErrorType";
                dlET.DataValueField = "ErrorType";
                dlET.DataBind();
                dlET.Items.FindByValue((e.Row.FindControl("lblET") as Label).Text).Selected = true;

                DropDownList dlAA = (DropDownList)e.Row.FindControl("dlAA");

                string AAquery = "select distinct AAA from ActualAgencyError";
                SqlCommand AAcmd = new SqlCommand(AAquery);
                dlAA.DataSource = GetData(AAcmd);
                dlAA.DataTextField = "AAA";
                dlAA.DataValueField = "AAA";
                dlAA.DataBind();
                dlAA.Items.FindByValue((e.Row.FindControl("lblAA") as Label).Text).Selected = true;

                DropDownList dlSupport = (DropDownList)e.Row.FindControl("dlSupport");

                string SupQuery = "select distinct Support from Support";
                SqlCommand Supcmd = new SqlCommand(SupQuery);
                dlSupport.DataSource = GetData(Supcmd);
                dlSupport.DataTextField = "Support";
                dlSupport.DataValueField = "Support";
                dlSupport.DataBind();
                dlSupport.Items.FindByValue((e.Row.FindControl("lblSupport") as Label).Text).Selected = true;

            }
        }

        protected void UpdateSummary(object sender, GridViewUpdateEventArgs e)
        {
            MyVariables.AT = dlAnnoType.SelectedValue;
            //dlAnnoType.DataBind();
            MyVariables.JN = dlJobName.SelectedValue;
            //dlJobName.DataBind();
            MyVariables.ST = dlStage.SelectedValue;
            //dlStage.DataBind();
            MyVariables.PI = gvSummary.PageIndex;
            //gvSummary.DataBind();

            string BU = (gvSummary.Rows[e.RowIndex].FindControl("dlBU") as DropDownList).SelectedItem.Value;
            string ET = (gvSummary.Rows[e.RowIndex].FindControl("dlET") as DropDownList).SelectedItem.Value;
            string AA = (gvSummary.Rows[e.RowIndex].FindControl("dlAA") as DropDownList).SelectedItem.Value;
            string PA = (gvSummary.Rows[e.RowIndex].FindControl("dlPA") as DropDownList).SelectedValue;
            string AnnotationNumber = gvSummary.DataKeys[e.RowIndex].Value.ToString();
            string sgkComments = (gvSummary.Rows[e.RowIndex].FindControl("tbsgkComm") as TextBox).Text;
            string Support = (gvSummary.Rows[e.RowIndex].FindControl("dlSupport") as DropDownList).SelectedValue;
            string SupportName = (gvSummary.Rows[e.RowIndex].FindControl("tbSupportName") as TextBox).Text;
            string BusImpact = (gvSummary.Rows[e.RowIndex].FindControl("tbBusImpact") as TextBox).Text;

            string strConnString = ConfigurationManager.ConnectionStrings["SRM_MetricConnectionString"].ConnectionString;
            using (SqlConnection con = new SqlConnection(strConnString))
            {
                string query = "update vw_GridviewSource set [BusinessUnit] = @BU, [ErrorType] = @ET, [sgkComments] = @sgk, [ActualAgencyError] = @AA, [PA] = @PA, [Support] = @Support, [SupportName] = @SupportName, [BusImpact] = @BusImpact where [AnnotationNumber] = @AnnoNum";
                using (SqlCommand cmd = new SqlCommand(query))
                {
                    cmd.Connection = con;
                    cmd.Parameters.AddWithValue("@BU", BU);
                    cmd.Parameters.AddWithValue("@AnnoNum", AnnotationNumber);
                    cmd.Parameters.AddWithValue("@ET", ET);
                    cmd.Parameters.AddWithValue("@AA", AA);
                    cmd.Parameters.AddWithValue("@sgk", sgkComments);
                    cmd.Parameters.AddWithValue("@PA", PA);
                    cmd.Parameters.AddWithValue("@Support", Support);
                    cmd.Parameters.AddWithValue("@SupportName", SupportName);
                    cmd.Parameters.AddWithValue("@BusImpact", BusImpact);

                    con.Open();
                    cmd.ExecuteNonQuery();
                    con.Close();
                    Response.Redirect(Request.Url.AbsoluteUri);
                }
            }
            gvSummary.PageIndex = MyVariables.PI;
            gvSummary.DataBind();

            BindData();
        }

        private void BindData()
        {
            gvSummary.PageIndex = MyVariables.PI;
            gvSummary.DataBind();

            if (MyVariables.JN != "" && MyVariables.ST != "" && MyVariables.AT != "")
            {
                dlJobName.SelectedValue = MyVariables.JN;
                dlJobName.DataBind();
                dlStage.SelectedValue = MyVariables.ST;
                dlStage.DataBind();
                dlAnnoType.SelectedValue = MyVariables.AT;
                dlAnnoType.DataBind();
            }
            gvSummary.PageIndex = MyVariables.PI;
            gvSummary.DataBind();

            String conString = System.Configuration.ConfigurationManager.ConnectionStrings["SRM_MetricConnectionString"].ConnectionString;
            string query = "select [Page_ID],[AnnotationNumber],[AnnotationBy],[PA],[AnnotationType],[BusinessUnit] as Unit,[ErrorType],[ActualAgencyError],AnnotationComments,[sgkComments],[ActualAgencyError],Support,SupportName, BusImpact,Cust from vw_GridviewSource order by [Page_ID]";

            SqlCommand cmd = new SqlCommand();

            if (dlJobName.SelectedValue != "" & dlStage.SelectedValue != "")
            {
                query = "select [Page_ID],[AnnotationNumber],[AnnotationBy],[PA],[AnnotationType],[BusinessUnit] as Unit,[ErrorType],[ActualAgencyError],AnnotationComments,[sgkComments],[ActualAgencyError],Support,SupportName, BusImpact,Cust from vw_GridviewSource where Name = '" + dlJobName.SelectedValue + "' and AnnotationDate = '" + dlStage.SelectedValue + "' order by [Page_ID]";
                //cmd.Parameters.AddWithValue("@Name", dlJobName.SelectedValue);
                //cmd.Parameters.AddWithValue("@Stage", dlStage.SelectedValue);
            }


            if (dlAnnoType.SelectedValue != "" && (dlJobName.SelectedValue.Length < 2 && dlStage.SelectedValue.Length < 2))
            {
                query = "select [Page_ID],[AnnotationNumber],[AnnotationBy],[PA],[AnnotationType],[BusinessUnit] as Unit,[ErrorType],[ActualAgencyError],AnnotationComments,[sgkComments],[ActualAgencyError],Support,SupportName, BusImpact,Cust from vw_GridviewSource where AnnotationType = '" + dlAnnoType.SelectedValue + "' order by [Page_ID]";
            }

            if (dlAnnoType.SelectedValue != "" && (dlJobName.SelectedValue != "" && dlStage.SelectedValue != ""))
            {
                query = "select [Page_ID],[AnnotationNumber],[AnnotationBy],[PA],[AnnotationType],[BusinessUnit] as Unit,[ErrorType],[ActualAgencyError],AnnotationComments,[sgkComments],[ActualAgencyError],Support,SupportName, BusImpact,Cust from vw_GridviewSource where AnnotationType = '" + dlAnnoType.SelectedValue + "' and Name = '" + dlJobName.SelectedValue + "' and AnnotationDate = '" + dlStage.SelectedValue + "' order by [Page_ID]";
            }

            cmd.CommandText = query;
            SqlConnection con = new SqlConnection(conString);
            cmd.CommandType = CommandType.Text;
            cmd.Connection = con;
            SqlDataAdapter sda = new SqlDataAdapter(cmd);
            DataSet ds = new DataSet();
            sda.Fill(ds);
            gvSummary.DataSource = ds;
            gvSummary.PageIndex = MyVariables.PI;
            gvSummary.DataBind();

        }
        private DataTable GetData(SqlCommand cmd)
        {
            string strConnString = ConfigurationManager.ConnectionStrings["SRM_MetricConnectionString"].ConnectionString;
            using (SqlConnection con = new SqlConnection(strConnString))
            {
                using (SqlDataAdapter sda = new SqlDataAdapter())
                {
                    cmd.Connection = con;
                    sda.SelectCommand = cmd;
                    using (DataTable dt = new DataTable())
                    {
                        sda.Fill(dt);
                        return dt;
                    }
                }
            }
        }

        protected void dlJobName_SelectedIndexChanged(object sender, EventArgs e)
        {
            MyVariables.JN = dlJobName.SelectedValue;
            dlJobName.DataBind();
            MyVariables.ST = dlStage.SelectedValue;
            dlStage.DataBind();
            MyVariables.AT = dlAnnoType.SelectedValue;
            dlAnnoType.DataBind();

            BindData();
            MyVariables.PI = gvSummary.PageIndex;
            gvSummary.DataBind();
        }
        protected void dlStage_SelectedIndexChanged(object sender, EventArgs e)
        {
            MyVariables.JN = dlJobName.SelectedValue;
            //dlStage.DataBind();
            MyVariables.ST = dlStage.SelectedValue;
            MyVariables.AT = dlAnnoType.SelectedValue;
            gvSummary.DataBind();
            BindData();
        }
        protected void dlAnnoType_SelectedIndexChanged(object sender, EventArgs e)
        {
            MyVariables.AT = dlAnnoType.SelectedValue;
            MyVariables.JN = dlJobName.SelectedValue;
            //dlStage.DataBind();
            MyVariables.ST = dlStage.SelectedValue;
            gvSummary.DataBind();
            BindData();
        }


    }
}

TIA

Tim Vavra

AnswerRe: Dropdown list based on another dropdown list. Pin
Richard Deeming19-Nov-13 2:07
mveRichard Deeming19-Nov-13 2:07 
QuestionASP.NET QUESTION PERSONAL PROJECT Pin
cserakeshcseranjan18-Nov-13 4:30
cserakeshcseranjan18-Nov-13 4:30 
AnswerRe: ASP.NET QUESTION PERSONAL PROJECT Pin
Joshua Omundson18-Nov-13 4:58
Joshua Omundson18-Nov-13 4:58 
AnswerRe: ASP.NET QUESTION PERSONAL PROJECT Pin
thatraja18-Nov-13 4:59
professionalthatraja18-Nov-13 4:59 
QuestionHow does IIS recognize that request is for MVC Controllers or webforms Pages? Pin
sanjay24365718-Nov-13 4:08
sanjay24365718-Nov-13 4:08 
QuestionJanus GridEx + asp.net Pin
jojoba201118-Nov-13 4:00
jojoba201118-Nov-13 4:00 
QuestionRe: Janus GridEx + asp.net Pin
thatraja18-Nov-13 4:32
professionalthatraja18-Nov-13 4:32 
QuestionRe: Janus GridEx + asp.net Pin
jojoba201119-Nov-13 18:05
jojoba201119-Nov-13 18:05 
QuestionADO.NET Pin
rock_monu17-Nov-13 21:58
rock_monu17-Nov-13 21:58 
AnswerRe: ADO.NET Pin
Rockstar_17-Nov-13 22:26
professionalRockstar_17-Nov-13 22:26 
AnswerRe: ADO.NET Pin
Richard MacCutchan17-Nov-13 22:36
mveRichard MacCutchan17-Nov-13 22:36 
AnswerRe: ADO.NET Pin
Abhinav S19-Nov-13 16:58
Abhinav S19-Nov-13 16:58 
QuestionHow to put the Datapager's numeric pager field back to one every selected index changed of dropdownlist? Pin
Member 840570016-Nov-13 1:26
Member 840570016-Nov-13 1:26 
QuestionRole-based windows authentication Pin
#realJSOP14-Nov-13 6:33
mve#realJSOP14-Nov-13 6:33 
AnswerRe: Role-based windows authentication Pin
Richard Deeming14-Nov-13 6:51
mveRichard Deeming14-Nov-13 6:51 
GeneralRe: Role-based windows authentication Pin
#realJSOP14-Nov-13 7:05
mve#realJSOP14-Nov-13 7:05 
GeneralRe: Role-based windows authentication Pin
#realJSOP14-Nov-13 10:43
mve#realJSOP14-Nov-13 10:43 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.