Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. Web Development
  3. ASP.NET
  4. Trying to prevent the first dropdownlist value changing my database field unless I need to in C#

Trying to prevent the first dropdownlist value changing my database field unless I need to in C#

Scheduled Pinned Locked Moved ASP.NET
csharpdatabasegraphicsdesignsecurity
1 Posts 1 Posters 1 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N Offline
    N Offline
    Norris Chappell
    wrote on last edited by
    #1

    Hi, I am having an issue with my dropdownlist taking the first value in my list even though I didn't change that field. When I select EDIT it gives me that row that I need to edit but the dropdownlist shows the first value which is not correct. When I do gvAccountStaff_RowUpdating the dropdown changes to the first value. I would like to retain and show the correct database value.

    using System;
    using System.IO;
    using System.Configuration;
    using System.Collections;
    using System.Collections.Generic;
    using System.Data;
    using System.Drawing;
    using System.Data.SqlClient;
    using System.Web.UI;
    using System.Data.OleDb;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI.WebControls;
    using System.Web.UI.HtmlControls;
    using System.Web.UI.WebControls.WebParts;

    namespace StaffingWebParts.AccountStaffMaintenance
    {
    public partial class AccountStaffMaintenanceUserControl : UserControl
    {
    SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["SQLStaffingConn"].ConnectionString);
    SqlCommand cmd = new SqlCommand();

        protected void Page\_Load(object sender, EventArgs e)
        {
            lblMsg.Text = "";
            if (!Page.IsPostBack)
            {
                
                BindSubjectData();
                
            }
    
        }
       
        //call to bind gridview
       
        public class DropDownData
        {
            public DropDownData(int id, string displaytext)
            {
                iD = id;
                text = displaytext;
            }
            int iD;
            public int ID
            {
                get { return iD; }
                set { iD = value; }
            }
            string text;
            public string Text
            {
                get { return text; }
                set { text = value; }
            }
        }
        protected void gvAccountStaff\_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            
    
                if (e.Row.RowType == DataControlRowType.DataRow)
                {
                   
                    Control ctrl = e.Row.FindControl("ddlType");
                    if (ctrl != null)
                    {
                        conn.Close();
                        DropDownList dd = ctrl as DropDownList;
                        List lst = new List();
                        SqlCommand cmd = new SqlCommand("SELECT ID, Last
    
    1 Reply Last reply
    0
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • World
    • Users
    • Groups