Subject: pageload is not correct...
Posted By: pc_35 Post Date: 9/21/2006 8:24:51 AM
Hi,
     I have a dropdownlist with values like s1,p1. Always in the dropdownlist s1 value would be selected(default setting).The datagrid with all the records corresponding to s1 are displayed.Now when i select the p1 value from the dropdown list ,the datagrid with all the records corresponding to p1 are displayed.Below the datagrid i have pages like 1 2 3 4 ..for example,when i am on the third page with p1 in the dropdownlist i pick an userid value in the datagrid ,i edit the values in the update screen corresponding to that userid.I click the save button .Now the changes are saved to the database ,but after clicking the save button it should take me back to the third page where the datagrid table is there,but instead it goes back to the intial screen with dropdownlist having s1 selected.Please let me know how to fix this problem.


Reply By: dparsons Reply Date: 9/21/2006 9:09:42 AM
It sounds like you are rebinding everything to their initial state; when you save infromation back to the database how do you rebind your datagrid, dropdownlist?

--Stole this from a moderator

I will only tell you how to do it, not do it for you.  
Unless, of course, you want to hire me to do work for you.
Reply By: pc_35 Reply Date: 9/21/2006 4:07:54 PM
hi,
    I have the userid column in the datagrid to be a hyperlinkcolumn.Onclicking the userid ,the page_load event gets fired.In the page_load event,I have if(!Page.IsPostBack) and  i have the function call for dropdownlist default setting and binddata() function.In the savebutton function ,i have a call for binddata( ).Onclicking the save button the updated data gets saved in the database,but the datagrid is set to the initial or default setting.Please let me know how to fix this problem.what changes should i make to work correctly?

Reply By: dparsons Reply Date: 9/21/2006 7:49:38 PM
You are going to need to post some code so I can see what exactly is going on.

--Stole this from a moderator

I will only tell you how to do it, not do it for you.  
Unless, of course, you want to hire me to do work for you.
Reply By: pc_35 Reply Date: 9/25/2006 10:50:02 AM
hi,
I have posted the code :
 private void Page_Load(object sender, System.EventArgs e)
        {
                     txtFocus.Value="0";
                EditUsers.Enabled =false;
                m_User = new BusinessLogin();  
                cacheUser = new PTSCache();       
                CheckSession();
                         
                //LoadDDLDefaults();
                if(!Page.IsPostBack)
                {
                    
                    EditUsers.Enabled=false;
                    tsUserMaintenance.SelectedIndex = LIST_INDEX;
                    ChkAddChangeOnLogin.Checked =true;
                    ChkAddEnabled.Checked =true;
                    LoadDDLDefaults();             
                    BindData();
                    LoadUser();    
                }
                 
                this.tsUserMaintenance.Attributes.Add("onclick","SetFocus();");
        
        }

private void LoadDDLDefaults()
        {                   
            /*SETTING ROLE - DDL VALUES*/
            DataView Source;    
            Source=(DataView)cacheUser.GetObjectFromCache(TABLE_ROLE);
            if(GetObjectFromSession("UserRole").ToString()=="Admin")
            {
                Source.RowFilter ="";
                cmbRole.DataSource =Source;
                cmbRole.DataValueField= Source.Table.Columns["RoleCode"].ToString().Trim();
                cmbRole.DataTextField= Source.Table.Columns["RoleName"].ToString().Trim();
                cmbRole.DataBind();
                URole.Text ="1";
            }
            else
            {
                Source.RowFilter="RoleCode like 'SA%'";
                URole.Text="0";
            }
            cmbEditRoleCode.DataSource =Source;
            cmbEditRoleCode.DataValueField= Source.Table.Columns["RoleCode"].ToString().Trim() ;
            cmbEditRoleCode.DataTextField= Source.Table.Columns["RoleName"].ToString().Trim();
            cmbEditRoleCode.DataBind();
                    
            cmbAddRoleCode.DataSource =Source;
            cmbAddRoleCode.DataValueField= Source.Table.Columns["RoleCode"].ToString().Trim();
            cmbAddRoleCode.DataTextField= Source.Table.Columns["RoleName"].ToString().Trim();
            cmbAddRoleCode.DataBind();
    
            Source= null;

            /*SETTING AGENCY - DDL VALUES*/
            Source = (DataView)cacheUser.GetObjectFromCache(TABLE_AGENCY);
            cmbEditAgency.DataSource = Source;
            cmbEditAgency.DataValueField = Source.Table.Columns["Agency"].ToString().Trim();
            cmbEditAgency.DataTextField = Source.Table.Columns["AgencyName"].ToString().Trim();
            cmbEditAgency.DataBind();
                            
            cmbAddAgency.DataSource = Source;
            cmbAddAgency.DataValueField = Source.Table.Columns["Agency"].ToString().Trim();
            cmbAddAgency.DataTextField = Source.Table.Columns["AgencyName"].ToString().Trim();
            cmbAddAgency.DataBind();
                
            cmbAgency.DataSource = Source;
            cmbAgency.DataValueField = Source.Table.Columns["Agency"].ToString().Trim();
            cmbAgency.DataTextField = Source.Table.Columns["AgencyName"].ToString().Trim();
            cmbAgency.DataBind();
        }

        private void BindData()
        {
            string userID=null;
            userID= GetObjectFromSession("UserId").ToString();
            DataSet    dsUserDetails = new DataSet();
            switch(GetObjectFromSession("UserRole").ToString().Trim())
            {
                case "SAdmin":
                {
                    dsUserDetails = m_User.GetSOUsers(userID,GetObjectFromSession("Agency").ToString());
                    cmbEditAgency.SelectedValue= GetObjectFromSession("Agency").ToString();    
                    cmbAddAgency.SelectedValue=GetObjectFromSession("Agency").ToString();    
                    
                    cmbEditAgency.Enabled = false;
                    cmbAddAgency.Enabled =false;
                    
                    
                    lblAgency.Visible =false;cmbAgency.Visible =false;
                    lblRole.Visible=false;cmbRole.Visible =false;
                    dgrUserList.PageSize=1000;
                    break;
                }
                case "Admin":
                {
                    if(bindflg==0)
                    {
                        
                        cmbAgency.Items.Insert(0,"");cmbAgency.Items.Insert(1,"ALL");
                        cmbEditAgency.Items.Insert(0,"");
                        cmbAddAgency.Items.Insert(0,"");
                        cmbRole.Items.Insert(0,"ALL");
                        cmbRole.SelectedIndex =3;
                        cmbAgency.SelectedIndex=1;
                        cmbAddRoleCode.Items.Insert(0,"");
                        cmbEditRoleCode.Items.Insert(0,"");
                        
                        
                        
                    }
                    dsUserDetails = m_User.GetUser(cmbAgency.SelectedValue.ToString(),cmbRole.SelectedValue.ToString());
                    
                    break;
                }
            }
            dgrUserList.DataSource = dsUserDetails;
            DataView source = new DataView();
            
            dgrUserList.DataBind();            
            
            if(dgrUserList.Items.Count > 0)
            {
                dgrUserList.Visible =true;
                lblNoResultsFound.Visible = false;
            }
            else
            {
                dgrUserList.Visible = false;
                lblNoResultsFound.Visible = true;

            }
            if(dsUserDetails.Tables[0].Rows.Count <= dgrUserList.PageSize )
            {
                dgrUserList.PagerStyle.Visible=false;
            }
            else
            {
                dgrUserList.PagerStyle.Visible=true;
            }
        }


        private void btnSaveUserDetails_Click(object sender, System.EventArgs e)
                    {
            
                bool result1  = ValidateControls();

                if(!result1)
                {
                           bool    result  = PopulateEditDataSet();
                        
                        if(result)
                        {
                            m_User.UpdateUser(ud);
                            tsUserMaintenance.SelectedIndex = LIST_INDEX;
                            bindflg=1;
                            BindData();
                            
                        }
                        else
                        {
                        errorControl.ShowMessageFromXml("DATASET_DOES_NOT_EXIST",CustomPageControls.DisplayMode.Warning);
                        }

                }
                else
                {    EditUsers.Enabled = true;
                    tsUserMaintenance.SelectedIndex = EDIT_INDEX;
                    if((cmbEditRoleCode.SelectedIndex==1)||(cmbEditRoleCode.SelectedIndex==2))
                    {
                        cmbEditAgency.Enabled=false;
                    }
                    else
                    {
                        cmbEditAgency.Enabled=true;
                    }
                }
            
                   }
                    
        
loaduser()  function loads the screen with data in edit mode.I have not posted the code for loaduser() function.Please guide me to fix this problem.I need to fix it as soon as possible.

Reply By: pc_35 Reply Date: 9/26/2006 9:20:25 AM
hi,
I have posted the code :

 private void Page_Load(object sender, System.EventArgs e)
        {
                txtFocus.Value="0";
                EditUsers.Enabled =false;
                m_User = new BusinessLogin();  
                cacheUser = new PTSCache();       
                CheckSession();
                         
                if(!Page.IsPostBack)
                {
                    EditUsers.Enabled=false; 
                    tsUserMaintenance.SelectedIndex = LIST_INDEX;
                    ChkAddChangeOnLogin.Checked =true;
                    ChkAddEnabled.Checked =true; 
                    LoadDDLDefaults();             
                    BindData();
                    LoadUser();    
                }
                 
                this.tsUserMaintenance.Attributes.Add("onclick","SetFocus();");
        
        }



private void LoadDDLDefaults()
        {                   
            /*SETTING ROLE - DDL VALUES*/
            DataView Source;    
            Source=(DataView)cacheUser.GetObjectFromCache(TABLE_ROLE);
            if(GetObjectFromSession("UserRole").ToString()=="Admin")
            {
                Source.RowFilter ="";
                cmbRole.DataSource =Source;
                cmbRole.DataValueField= Source.Table.Columns["RoleCode"].ToString().Trim();
                cmbRole.DataTextField= Source.Table.Columns["RoleName"].ToString().Trim();
                cmbRole.DataBind();
                URole.Text ="1";
            }
            else
            {
                Source.RowFilter="RoleCode like 'SA%'";
                URole.Text="0";
            }
            cmbEditRoleCode.DataSource =Source;
            cmbEditRoleCode.DataValueField= Source.Table.Columns["RoleCode"].ToString().Trim() ;
            cmbEditRoleCode.DataTextField= Source.Table.Columns["RoleName"].ToString().Trim();
            cmbEditRoleCode.DataBind();
                    
            cmbAddRoleCode.DataSource =Source;
            cmbAddRoleCode.DataValueField= Source.Table.Columns["RoleCode"].ToString().Trim();
            cmbAddRoleCode.DataTextField= Source.Table.Columns["RoleName"].ToString().Trim();
            cmbAddRoleCode.DataBind();
    
            Source= null;

            /*SETTING AGENCY - DDL VALUES*/
            Source = (DataView)cacheUser.GetObjectFromCache(TABLE_AGENCY);
            cmbEditAgency.DataSource = Source;
            cmbEditAgency.DataValueField = Source.Table.Columns["Agency"].ToString().Trim();
            cmbEditAgency.DataTextField = Source.Table.Columns["AgencyName"].ToString().Trim();
            cmbEditAgency.DataBind();
                            
            cmbAddAgency.DataSource = Source;
            cmbAddAgency.DataValueField = Source.Table.Columns["Agency"].ToString().Trim();
            cmbAddAgency.DataTextField = Source.Table.Columns["AgencyName"].ToString().Trim();
            cmbAddAgency.DataBind();
                
            cmbAgency.DataSource = Source;
            cmbAgency.DataValueField = Source.Table.Columns["Agency"].ToString().Trim();
            cmbAgency.DataTextField = Source.Table.Columns["AgencyName"].ToString().Trim();
            cmbAgency.DataBind();
        }


        private void BindData()
        {
            string userID=null;
            userID= GetObjectFromSession("UserId").ToString(); 
            DataSet    dsUserDetails = new DataSet();
            switch(GetObjectFromSession("UserRole").ToString().Trim())
            {
                case "SAdmin":
                {
                    dsUserDetails = m_User.GetSOUsers(userID,GetObjectFromSession("Agency").ToString());
                    cmbEditAgency.SelectedValue= GetObjectFromSession("Agency").ToString();    
                    cmbAddAgency.SelectedValue=GetObjectFromSession("Agency").ToString();    
                    
                    cmbEditAgency.Enabled = false; 
                    cmbAddAgency.Enabled =false;
                    
                    
                    lblAgency.Visible =false;cmbAgency.Visible =false;
                    lblRole.Visible=false;cmbRole.Visible =false;
                    dgrUserList.PageSize=1000;
                    break;
                }
                case "Admin":
                {
                    if(bindflg==0)
                    {
                        
                        cmbAgency.Items.Insert(0,"");cmbAgency.Items.Insert(1,"ALL");
                        cmbEditAgency.Items.Insert(0,"");
                        cmbAddAgency.Items.Insert(0,"");
                        cmbRole.Items.Insert(0,"ALL");
                        cmbRole.SelectedIndex =3;
                        cmbAgency.SelectedIndex=1;
                        cmbAddRoleCode.Items.Insert(0,"");
                        cmbEditRoleCode.Items.Insert(0,"");
                        
                        
                        
                    }
                    dsUserDetails = m_User.GetUser(cmbAgency.SelectedValue.ToString(),cmbRole.SelectedValue.ToString());
                    
                    break;
                }
            }
            dgrUserList.DataSource = dsUserDetails;
            DataView source = new DataView();
            
            dgrUserList.DataBind();            
            
            if(dgrUserList.Items.Count > 0)
            {
                dgrUserList.Visible =true;
                lblNoResultsFound.Visible = false;
            }
            else
            {
                dgrUserList.Visible = false;
                lblNoResultsFound.Visible = true;

            }
            if(dsUserDetails.Tables[0].Rows.Count <= dgrUserList.PageSize )
            {
                dgrUserList.PagerStyle.Visible=false;
            }
            else
            {
                dgrUserList.PagerStyle.Visible=true;
            } 
        }



        private void btnSaveUserDetails_Click(object sender, System.EventArgs e)
                    {
            
                bool result1  = ValidateControls();

                if(!result1)
                {
                           bool    result  = PopulateEditDataSet();
                        
                        if(result)
                        {
                            m_User.UpdateUser(ud);
                            tsUserMaintenance.SelectedIndex = LIST_INDEX;
                            bindflg=1;
                            BindData(); 
                            
                        }
                        else
                        {
                        errorControl.ShowMessageFromXml("DATASET_DOES_NOT_EXIST",CustomPageControls.DisplayMode.Warning);
                        }

                }
                else
                {    EditUsers.Enabled = true;
                    tsUserMaintenance.SelectedIndex = EDIT_INDEX;
                    if((cmbEditRoleCode.SelectedIndex==1)||(cmbEditRoleCode.SelectedIndex==2))
                    {
                        cmbEditAgency.Enabled=false;
                    }
                    else
                    {
                        cmbEditAgency.Enabled=true;
                    }
                }
            
                   }
    
                
        
loaduser()  function loads the screen with data in edit mode.I have not posted the code for loaduser() function.Please guide me to fix this problem.I need to fix it as soon as possible.




Go to topic 50249

Return to index page 165
Return to index page 164
Return to index page 163
Return to index page 162
Return to index page 161
Return to index page 160
Return to index page 159
Return to index page 158
Return to index page 157
Return to index page 156