Click here to Skip to main content
15,914,243 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I have a dropdownlist in side a gridview, Onselectedindexchanged I want to some action. But it doing postback but I don't want postback.Can any one helpme out in stoping the PostBack.I also used Updatepanel but after that the action what I want its not happening.

Below is my code for .cs

C#
protected void Page_Load(object sender, EventArgs e)
   {
       if (!IsPostBack)
       {

           if (this.UserContext.UserRoles.Length == 0)
           {
               Response.Redirect("./Default.aspx");
           }
           if (!IsUserInRole(Constants.RL_GETSSET))
           {
               Response.Redirect("./Default.aspx");
           }

           adminBO = new UpdateAdminBO(this.UserContext);
           btnRemove.Visible = false;
           listSupportRoles = new DomainByCodeValue(this.UserContext, CategotyCode.SUPPORT_ROLES).DomainCodeValue;
           listClarifyRegions = new DomainByCodeValue(this.UserContext, CategotyCode.CLARIFY_REGION).DomainCodeValue;
           ViewState["listClarifyRegions"] = listClarifyRegions;
           existingUserDetails = adminBO.GetUserDetails();
           // Selected Option.
           // Q4 Requirements
           if (!IsPostBack)
           {
               ddlUserRoleSelect.DataSource = listSupportRoles;
               ddlUserRoleSelect.DataTextField = "CodeValue";
               ddlUserRoleSelect.DataValueField = "CodeID";
               ddlUserRoleSelect.DataBind();
               ddlUserRoleSelect.Items.Insert(0, new ListItem("ALL", "1"));
               this.BindData();

               ddlAddUser.DataSource = listSupportRoles;
               ddlAddUser.DataTextField = "CodeValue";
               ddlAddUser.DataValueField = "CodeID";
               ddlAddUser.DataBind();
               ddlAddUser.Items.Insert(0, new ListItem("Select User Role", "1"));

               rcbRegions.DataSource = ViewState["listClarifyRegions"];
               rcbRegions.DataTextField = "CodeValue";
               rcbRegions.DataValueField = "CodeID";
               rcbRegions.DataBind();


               ddlUserRole.DataSource = listSupportRoles;
               ddlUserRole.DataTextField = "CodeValue";
               ddlUserRole.DataValueField = "CodeID";
               ddlUserRole.DataBind();
               ddlUserRole.Items.Insert(0, new ListItem("ALL", "1"));

               //V-sisann Removed Code.
               if (Request.QueryString["id"] != null)
               {
                   ScriptManager scriptManager = ScriptManager.GetCurrent(Page);
                   ScriptManager.RegisterClientScriptBlock(BtnUpdate, Page.GetType(), "MsgType_Info", "doShowMsg(\"New User Updated successfully.\", MsgType_Info)", true);
               }
           }
       }
   }



C#
protected void ddlUserRole_SelectedIndexChanged(object sender, EventArgs e)
    {

        //get user role drop down list
        DropDownList ddlRole = (DropDownList)sender;

        //get selected userrole row
        GridViewRow row = (GridViewRow)ddlRole.NamingContainer;

        ////get inner grid
        //GridView gridInner = (GridView)row.NamingContainer;

        ////get user detials grid
        //GridView gridUserDetails = (GridView)gridInner.NamingContainer;

        //System.Web.UI.HtmlControls.HtmlImage img = (HtmlImage)gridUserDetails.NamingContainer.FindControl("imgDetail");

        Telerik.Web.UI.RadComboBox rcbSecondaryUserRole = row.FindControl("rcbSecondaryUserRole") as RadComboBox;

        if (ddlRole.SelectedItem.Text == "GSPO")
        {
            rcbSecondaryUserRole.DataSource = ViewState["listClarifyRegions"];
            rcbSecondaryUserRole.DataTextField = "CodeValue";
            rcbSecondaryUserRole.DataValueField = "CodeID";
            rcbSecondaryUserRole.DataBind();
            rcbSecondaryUserRole.Visible = true;
        }   
        else
        {
            rcbSecondaryUserRole.Visible = false;
        }
    }
Posted
Comments
Prasad Khandekar 24-Apr-13 10:19am    
Set the AutoPostBack property to false.
Sandeep Mewara 24-Apr-13 11:17am    
+5
Fayaz7Wonders 25-Apr-13 1:15am    
Hey Prasad ,
If I set the AutoPostBack to false then the ddlSelectedIndexChanged event will not fire.
Prasad Khandekar 25-Apr-13 1:25am    
Well it works like that. Since it's not very clear on what action you want to happen upon selecting the item, I can suggest you try JQuery AJax to call the server side action.
Fayaz7Wonders 25-Apr-13 1:55am    
My Question is when ddlUserRole_SelectedIndexChanged event will fire it should not do the Post back.Because of post back my controls are again getting refreshed.I am not able to stay in the same position.

Do you have any Idea on JQuery for this.Can u plz share

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



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