Prevent selectedindexchange to be fired

Hi,

I have a gridview that:
- moves to another page when SelectedIndexChanged event is fired when a row is selected
- Has a delete button, with a confirm button extender, to delete the row

So When I click on the delete button, the message to delete the row is fired, then the SelectedIndexChanged event is fired, so the DeleteRowCommand never happens.

How can I prevent the SelectedIndexChanged from being fired?

Thank you for your help

Code below:

In the ascx control:
<asp:GridView ID="GridView1" runat="server" DataSourceID="DS" DataKeyNames="JobID" 
OnRowDataBound="GV_RowDataBound" OnSelectedIndexChanged="GV_SelectedIndexChanged" OnDataBound="GV_DataBound" 
Caption="Bundled jobs">
    <Columns>
        <asp:TemplateField HeaderText="Job number">
            <ItemTemplate>
                <asp:Label ID="lblJobRefNo" runat="server" Text='<%# Eval("JobRefNo") %>' Visible="True" Font-Bold='<%# Eval("IsBold") %>' />
            </ItemTemplate>
        </asp:TemplateField>
        <asp:TemplateField HeaderText="Remove Job">
            <ItemTemplate>
                <asp:ImageButton ID="btnDelete" runat="server" AlternateText="Del"
                ImageUrl="~/App_Themes/Default/Images/Buttons/btnDelete.gif" ImageAlign="middle" 
                CommandName="Delete" CommandArgument='<%# Eval("JobID") %>' OnCommand="DeleteJob_RowCommand" Visible='<%# Eval("IsEnabled") %>' />
                <asp:ConfirmButtonExtender ID="cnfmBtnExt" runat="server" TargetControlID="btnDelete" 
                ConfirmText="Are you sure you want to remove this job from the bundle?"/>
            </ItemTemplate>
        </asp:TemplateField>
    </Columns>
</asp:GridView>

Open in new window


In the ascx.cs code:
    protected void GV_SelectedIndexChanged(object sender, EventArgs e)
    {

        if (this.LJobID != int.Parse(GV.SelectedDataKey[0].ToString()))
        {
            this.LJobID = int.Parse(GV.SelectedDataKey[0].ToString());

        EventHandler handler = SelectJob;
                if (SelectJob!=null)
                    handler(sender, e);
        }
    }

    protected void DeleteJob_RowCommand(object sender, System.Web.UI.WebControls.CommandEventArgs e)
    {

        GridViewRow GVRow = (GridViewRow)((ImageButton)sender).NamingContainer;
        int JobID = int.Parse(((HiddenField)GVRow.FindControl("hfJobID")).Value);

        DTO.AssocBundle d = new DTO.AssocBundle();
        BLL.AssocBundle DL = new BLL.AssocBundle();
        d.JobID = JobID;
        d.LJobID = LJobID;
        d.UpdatedBy = NVar.UserName;
        d.UpdType = "Delete";

        DL.UpdateData(d);
        this.GV.DataBind();
    }

Open in new window

AnneFAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Rahul AgarwalTeam LeaderCommented:
I think there is no way to avoid it

e.Row.Cells(i).Attributes("ondblclick") = Page.ClientScript.GetPostBackClientHyperhttp://www.aspforums.net/this.gvTask, "Select$" + e.Row.RowIndex;


change ( to [ and ) to ]

Reference:
http://www.aspforums.net/Threads/538810/Prevent-SelectedIndexChanged-event-to-fire-on-checkbox-checked-in-GridView-in-ASPNet/
0
guru_samiCommented:
I just added your deleted column code to one of a sample GV. I see that DeleteRowCommand was fired and then RowCommand was fired but not SelectedIndexChanged.

Is there something else in your code-behind we are missing?
0
AnneFAuthor Commented:
Yes, there is a bit of code missing. The control is in a form,and the SelectedIndexChanged is fired from this form.

Code below:
In the aspx form:
  <pts:AssociatedBundle ID="ctlAssociatedBundle" runat="server" OnSelectJob="AssocBundle_Select"/>   

Open in new window

In the aspx.cs Code:
    protected void AssocBundle_Select(object sender, EventArgs e) 
    {
        _JobID = this.ctlAssociatedBundle.LJobID;
        _IsAimpd = this.ctlJob.IsAimpd;

        SetupQS("Set");
    }

Open in new window

SetupQS - Set or retrieve the parameters of the query string and redirect to a page with new parameters:
   protected void SetupQS(string status)
        {
        UrlManager url = new UrlManager();

        switch (status)
        {
            case "Set":
                using (QSH QH =new QSH())
                {
                    QH.UrlType = _UrlType;
                    QH.UrlGroup = _urlGroup;
                    QH.BaseUrl = url.GetUrl(_UrlType);
                    QH.MenuIndex = _MenuIndex.ToString();
                    QH.MenuName = _MenuName;
                    QH.OpID = _EmpID.ToString();
                    QH.OpDesc = _EmpName;
                    QH.EmpType = _EmpType;
                    QH.DocID = _DocID.ToString();
                    QH.JobID = _JobID.ToString();
                    QH.IsAimpd = _IsAimpd.ToString();
                    Response.Redirect(QH.NavigateUrl);
        }
                   break;

            case "Retrieve":
                using (QSH QH =new QSH(Request.QueryString))
            {
                        _urlGroup = QH.UrlGroup;
                        _UrlType = QH.UrlType;
                        _MenuIndex = int.Parse(QH.MenuIndex);
                        _MenuName = QH.MenuName;
                        _EmpID = int.Parse(QH.OpID);
                        _EmpName = QH.OpDesc;
                        _EmpType = QH.EmpType;
                        _DocID = int.Parse(QH.DocID);
                        _JobID = int.Parse(QH.JobID);
                        _IsAimpd = int.Parse(QH.IsAimpd);
            }
            break;
        }
    }

Open in new window

Thanks
0
Learn Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

guru_samiCommented:
From what I am understanding, GV SelectedIndexChanged and SetupQS will not fired unless Select Command from GV is fired.
Are you calling SetupQS  from somewhere else?
0
AnneFAuthor Commented:
Hi,
Yes, you are right. GV SelectedIndexChanged and SetupQS are only fired from the GV Select Command.
SetupQS is also called from  2 other similar gridviews in the same form.
And called as well in the Page_Load event, but to retrieve info from the Query string, SetupQS("Retrieve")
0
guru_samiCommented:
Can you share your page load?
Make sure setupqs is not called on postback.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
AnneFAuthor Commented:
Hi,
I found the solution. Thank you for your indirect help. I checked if SetupQS was called on postback and found that the problem was a validation to add a record that was not disabled to delete the record, therefore creating an error.
Thank you for your time, and questions asked.
0
AnneFAuthor Commented:
As I was following Guru_Sami suggestion, I found that the problem was somewhere else in the code.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.