[x]
Posted via EE Mobile

Search, ask, and monitor your questions on the go with EE Mobile. Visit Experts Exchange from your mobile device and never be out of touch again.

Question
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

8.8

Need to build a datagrid with the value of selected index from dropdownlist.

Asked by mathieu_cupryk in Programming for ASP.NET

Tags: datagrid

I need to build a datagrid with using the information that was used in from a dropdownlist.
I start of with a dropdownlist of code types. The user selects a code type and presses the button
and we want to use the index of the dropdownlist (CODE_TYPE_ID) to build the datagrid.

The select will be getting codes for a specific code type. SELECT CODE_DESC WHERE CODE_TYPE_ID = SELECTEDINDEX

This will be need to build the datagrid. Except I have problems getting started.
Here is the code: How should I go to modify the code?

public class codestypes : System.Web.UI.Page
      {
            protected System.Web.UI.WebControls.Label lblFullName;
            protected System.Web.UI.WebControls.TextBox newCountry;
            protected System.Web.UI.WebControls.TextBox newName;
            protected System.Web.UI.WebControls.DataGrid DataGrid1;
            protected System.Web.UI.WebControls.Label pathTitle;
            protected System.Web.UI.WebControls.Label typeName;
            protected System.Web.UI.WebControls.DropDownList DropDownList1;
            protected System.Web.UI.WebControls.Button Button1;
            protected System.Web.UI.WebControls.Button addCountry;
      
            private void Page_Load(object sender, System.EventArgs e)
            {
                  lblFullName.Text = PDM.varSession.getFullName();
                  
                  if (!Page.IsPostBack)
                  {
                        string strConn = ConfigurationSettings.AppSettings["CONNECTION_STRING_PDM"];                              
                        SqlConnection conDB = new SqlConnection(strConn);
                        SqlCommand myCMD;
                        myCMD = new SqlCommand("Select * From PDM_CODE_TYPES", conDB);
                        SqlDataAdapter adapter = new SqlDataAdapter(myCMD);
                        DataSet dataset = new DataSet();  
                        adapter.Fill(dataset,"PDM_CODE_TYPES");
                        // apply sort to the DefaultView to sort by CompanyName
                        dataset.Tables[0].DefaultView.Sort = "CODE_TYPE_NAME";
                        DropDownList1.DataSource = dataset.Tables["PDM_CODE_TYPES"].DefaultView;
                        DropDownList1.DataTextField = "CODE_TYPE_NAME"; // what to display
                        DropDownList1.DataValueField = "CODE_TYPE_ID"; // what to set as value
                        DropDownList1.DataBind();
                        BindData();
                  }
            }

            void BindData()
            {
                  string strConn = ConfigurationSettings.AppSettings["CONNECTION_STRING_PDM"];
                  SqlConnection conn = new SqlConnection(strConn);
                  SqlDataAdapter Cmd = new SqlDataAdapter(sql, conn);

                  DataSet DS = new DataSet();
                  conn.Open();
                  Cmd.Fill(DS);
                  DataGrid1.DataSource = DS;
                  DataGrid1.DataBind();
                  conn.Close();
            }


            #region Web Form Designer generated code
            override protected void OnInit(EventArgs e)
            {
                  //
                  // CODEGEN: This call is required by the ASP.NET Web Form Designer.
                  //
                  InitializeComponent();
                  base.OnInit(e);
            }
            
            /// <summary>
            /// Required method for Designer support - do not modify
            /// the contents of this method with the code editor.
            /// </summary>
            private void InitializeComponent()
            {    
                  this.DataGrid1.CancelCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.DataGrid1_CancelCommand);
                  this.DataGrid1.EditCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.DataGrid1_EditCommand);
                  this.DataGrid1.ItemDataBound += new System.Web.UI.WebControls.DataGridItemEventHandler(this.DataGrid1_ItemDataBound);
                  this.DropDownList1.SelectedIndexChanged += new System.EventHandler(this.DropDownList1_SelectedIndexChanged);
                  this.Button1.Click += new System.EventHandler(this.Button1_Click);
                  this.Load += new System.EventHandler(this.Page_Load);

            }
            #endregion

            private void DataGrid1_EditCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
            {
                  DataGrid1.EditItemIndex=e.Item.ItemIndex;
                  BindData();
            }

            private void DataGrid1_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
            {
                  if ((e.Item.ItemType == ListItemType.Item) || (e.Item.ItemType == ListItemType.AlternatingItem))
                  {
                        ((Button)e.Item.FindControl("edit")).Visible = true;
                        ((Button)e.Item.FindControl("update")).Visible = false;
                        ((Button)e.Item.FindControl("delete")).Visible = false;
                        ((Button)e.Item.FindControl("cancel")).Visible = false;

                        string bgColor;
                        if (e.Item.ItemType == ListItemType.Item)
                              bgColor = "#EFF5DA";
                        else
                              bgColor = "#F0FFBB";

                        Label currencyName = (Label)e.Item.FindControl("currencyName");
                        Label isoCode = (Label)e.Item.FindControl("iso");
                        
                        currencyName.Text = Convert.ToString(DataBinder.Eval(e.Item.DataItem, "NAME"));
                        isoCode.Text = Convert.ToString(DataBinder.Eval(e.Item.DataItem, "CODE"));

                        e.Item.Attributes.Add("onmouseover", "this.style.backgroundColor='#add8e6'");
                        e.Item.Attributes.Add("onmouseout", "this.style.backgroundColor='" + bgColor + "'");

                  }
                  if (e.Item.ItemType == ListItemType.EditItem)
                  {
                        ((Button)e.Item.FindControl("edit")).Visible = false;
                        ((Button)e.Item.FindControl("update")).Visible = true;
                        ((Button)e.Item.FindControl("delete")).Visible = true;
                        ((Button)e.Item.FindControl("cancel")).Visible = true;

                        TextBox txtName = (TextBox)e.Item.FindControl("txtName");
                        TextBox txtISO = (TextBox)e.Item.FindControl("txtISO");
                        HtmlInputHidden dbCurrencyName = (HtmlInputHidden)e.Item.FindControl("dbCurrencyName");
                        Label currencyID = (Label)e.Item.FindControl("currencyID");

                        txtName.Text = Convert.ToString(DataBinder.Eval(e.Item.DataItem, "NAME"));
                        txtISO.Text            = Convert.ToString(DataBinder.Eval(e.Item.DataItem, "code"));
                        dbCurrencyName.Value = Convert.ToString(DataBinder.Eval(e.Item.DataItem, "NAME"));
                        currencyID.Text = Convert.ToString(DataBinder.Eval(e.Item.DataItem, "ID"));
                  }


            }

            private void DataGrid1_CancelCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
            {
                  DataGrid1.EditItemIndex=-1;
                  BindData();

            }

            private void DropDownList1_SelectedIndexChanged(object sender, System.EventArgs e)
            {
            
            }

            private void Button1_Click(object sender, System.EventArgs e)
            {
            
            }
      }

Any help would be appreciated.
 
Loading Advertisement...
 
[+][-]02/16/05 01:10 PM, ID: 13328847Accepted Solution

View this solution now by starting your 30-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

About this solution

Zone: Programming for ASP.NET
Tags: datagrid
Sign Up Now!
Solution Provided By: NetDeveloper
Participating Experts: 2
Solution Grade: A
 
[+][-]02/16/05 11:27 AM, ID: 13327647Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]02/16/05 11:34 AM, ID: 13327717Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]02/16/05 11:50 AM, ID: 13327908Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]02/16/05 12:44 PM, ID: 13328565Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]02/16/05 12:51 PM, ID: 13328648Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]02/16/05 12:52 PM, ID: 13328664Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]02/16/05 01:08 PM, ID: 13328831Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]02/16/05 01:10 PM, ID: 13328850Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20091111-EE-VQP-92