Click here to Skip to main content
15,918,049 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
when i click on EDIT button the dropdownlist control of it is become empty
please send the C#solution of it..!!


Code:=

SqlConnection conn = new SqlConnection(System.Web.Configuration.WebConfigurationManager.AppSettings["ConnectionString"]);
    SqlDataAdapter da =new SqlDataAdapter();
    DataSet ds = new DataSet();
    SqlCommand cmd = new SqlCommand();
        protected void Page_Load(object sender, EventArgs e)
    {
        try
        {
        if (!IsPostBack)
        {
            populatedata();
            //BindData();
        }
    }
    catch (Exception ex)
    {
    }
                                                
    }

    public void populatedata()
    {
        try
        {
            if (conn.State == ConnectionState.Closed)
            {
                conn.Open();
            }
            cmd.CommandText = "select O.Order_ID,O.Package_ID,O.No_Of_Images,SC.Package_Name,SC.Package_ID,O.Remarks,O.Original_Quote_Amount,O.Revised_Quote_Amount,O.Amount_Received,(O.Revised_Quote_Amount-O.Amount_Received) As Balance_Amount,O.Status_Code from tbl_mst_Order O,tbl_mst_Service_Catalogue SC where O.Package_ID=SC.Package_ID";
            cmd.Connection = conn;
            da = new SqlDataAdapter(cmd);
            da.Fill(ds, "tbl_mst_Order");
            cmd.ExecuteNonQuery();
            //Gdordermgmt.DataSource = ds;
           // Gdordermgmt.DataBind();
            cmd.CommandText = "Select Status_Id, Status_Code,Status_Description from tbl_mst_Order_Status where Is_Status_Active=1";
            cmd.Connection = conn;
            da = new SqlDataAdapter(cmd);
            da.Fill(ds, "tbl_mst_Order_Status");
            cmd.ExecuteNonQuery();
            BindData();
        }
        catch (Exception ex)
        {
        }
            finally
            {
                conn.Close();
            }
    }
    protected void BindData()
    {
        Gdordermgmt.DataSource = ds.Tables["tbl_mst_Order"];
        Gdordermgmt.DataBind();
    }
    protected void Gdordermgmt_PageIndexChanged(object sender, DataGridPageChangedEventArgs e)
    {
        try
        {
            Gdordermgmt.CurrentPageIndex = e.NewPageIndex;
            populatedata();
            //BindData();
        }
        catch(Exception ex)
        {
        }
       // Gdordermgmt.DataSource = ds;
        //Gdordermgmt.DataBind();
      // BindData();
    }
    public void Gdordermgmt_editcmd(object sender, DataGridCommandEventArgs e)
    {          
      
      Gdordermgmt.EditItemIndex = e.Item.ItemIndex;
      populatedata();
      //BindData();
       //ResetPageIndex(Gdordermgmt,View);
      //BindData();
    
    }
   
    protected void Gdordermgmt_cancelcmd(object sender, DataGridCommandEventArgs e)
    {
        Gdordermgmt.EditItemIndex = -1;
        populatedata();
        //BindData();
      
      //  Gdordermgmt.DataSource = ds;
       // Gdordermgmt.DataBind();
       // BindData();
    }
        protected void Gdordermgmt_updatecmd(object sender, DataGridCommandEventArgs e)
      {
          TextBox txtamtrecieved = (TextBox)e.Item.FindControl("txtamtrecieved");
          TextBox txtrevisedqtamt = (TextBox)e.Item.FindControl("txtrevisedqtamt");
          TextBox tx = new TextBox();
          tx = (TextBox)e.Item.Cells[8].Controls[0];
          //cmd.CommandType = CommandType.Text;
          cmd.CommandText = "Update tbl_mst_Order" +
                           " Set Revised_Quote_Amount= '" + txtrevisedqtamt.Text + "', Received_Amount='" + txtamtrecieved.Text + "'where Order_ID='" + e.Item.ItemIndex + "'";
          cmd.Parameters.Add(new SqlParameter("@txtrevisedqtamt", SqlDbType.Text));
          cmd.Parameters["@txtrevisedqtamt"].Value = tx.Text;
          cmd.ExecuteNonQuery();
          ds.AcceptChanges();
          Gdordermgmt.EditItemIndex = -1;
          Gdordermgmt.DataBind();
          //da.Update(ds);
   
       }
    protected void Gdordermgmt_Bounddata(object sender, DataGridItemEventArgs e)
    {
        if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
        {
            DropDownList list = (DropDownList)e.Item.FindControl("ddlorderstatus");
            if (list != null)
            {
                list.DataSource = ds.Tables["tbl_mst_Order_Status"];
                list.DataValueField = ds.Tables["tbl_mst_Order_Status"].Columns[0].ToString();
                list.DataTextField= ds.Tables["tbl_mst_Order_Status"].Columns[1].ToString();
                list.DataBind();
            }
        }
        else
        {
        }
    }
Posted
Updated 25-Mar-10 1:15am
v2

1 solution

I think first you need to understand how web applications works, ASP.NET does not maintain state, you have loaded the dataset from database in the not isPostback of the page load.

When user perfoms any operation on the page and perform the postback then the data present in your dataset is lost, it contains nothing, that’s why you are not getting any data in the dropdown list.

Member 6967450 wrote:
protected void Page_Load(object sender, EventArgs e)    
    {        
            try
               {        
                 if (!IsPostBack)        
                    {            
                     populatedata();            //BindData();        
                     }   
              }    catch (Exception ex)      {    }                                                    }





You can do any one of the following options.

1- Persist the data present the the dataset by storing it into viewstate or session (Not a good approach if your userbase is big or the data is huge)

2- To bind the dropdown list, load the data again from the database
 
Share this answer
 
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900