Wrox Programmer Forums
|
ASP.NET 1.0 and 1.1 Basics ASP.NET discussion for users new to coding in ASP.NET 1.0 or 1.1. NOT for the older "classic" ASP 3 or the newer ASP.NET 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.0 and 1.1 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old September 21st, 2006, 08:24 AM
Registered User
 
Join Date: Sep 2006
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default pageload is not correct...

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.


 
Old September 21st, 2006, 09:09 AM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

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.
 
Old September 21st, 2006, 04:07 PM
Registered User
 
Join Date: Sep 2006
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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?

 
Old September 21st, 2006, 07:49 PM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

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.
 
Old September 25th, 2006, 10:50 AM
Registered User
 
Join Date: Sep 2006
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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","S etFocus();");

        }

private void LoadDDLDefaults()
        {
            /*SETTING ROLE - DDL VALUES*/
            DataView Source;
            Source=(DataView)cacheUser.GetObjectFromCache(TABL E_ROLE);
            if(GetObjectFromSession("UserRole").ToString()=="A dmin")
            {
                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_AGENC Y);
            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("Age ncy").ToString());
                    cmbEditAgency.SelectedValue= GetObjectFromSession("Agency").ToString();
                    cmbAddAgency.SelectedValue=GetObjectFromSession("A gency").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.Inser t(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)||(cmbEditRol eCode.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.

 
Old September 26th, 2006, 09:20 AM
Registered User
 
Join Date: Sep 2006
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

hi,
I have posted the code :
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();");

        }
Code:
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();
        }
Code:
        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;
            } 
        }
Code:
        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.








Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem with accessing function in pageload method nelly78 .NET Framework 2.0 5 September 8th, 2008 06:49 AM
Is it correct like this ? tunisiano C# 1 March 7th, 2007 12:22 PM
Correct code stefanocinfo BOOK: Professional PHP 5 ISBN: 978-0-7645-7282-1 2 October 4th, 2006 03:06 AM
correct syntax? crmpicco Classic ASP Basics 2 February 10th, 2005 05:32 AM
Overrinding PageLoad help! Bobafett ASP.NET 1.0 and 1.1 Basics 6 September 7th, 2004 10:20 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.