Link to home
Start Free TrialLog in
Avatar of daforga
daforga

asked on

Gridview Button not firing on first click

This works but only on the 2nd click of the gridview button.  Following is the code I have used.  Any help is appreciated.

I have constructed a gridview
            <asp:GridView ID="gvAction" runat="server"
                           AutoGenerateColumns="False"
                           SkinID="GridViewCTELNopaging"
                           onrowdatabound = "gvAction_RowDataBound" > 
with a button in a template field.  
                     <asp:TemplateField HeaderText="Edit">
                         <ItemTemplate>
                             <asp:Button ID="btnActionGridSearch" runat="server" CommandName="EditAction"
                                 Text="Edit" OnClick = "btnActionGridSearch_Click"  />
                         </ItemTemplate>
                     </asp:TemplateField>
In code behind:
rowdatabound:
       protected void gvAction_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            GridView gv = (GridView)sender;
            RowCount = e.Row.RowIndex;
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                 e.Row.Style["cursor"] = "hand";
                btn = (Button)e.Row.FindControl("btnActionGridSearch");
                btn.Attributes.Add("rowNumber", RowCount.ToString());
                btn.ID = RowCount.ToString();
                e.Row.Cells[1].Style.Add("display", "none");
            }
        }
button click:
        protected void btnActionGridSearch_Click(object sender, EventArgs e)
        {
            //Go to hidden panel to display the Followups specific to this opportunity
            Button btn = (Button)sender;
            string it = btn.Attributes["rowNumber"].ToString();
            int TheRow = Convert.ToInt16(it);
            string ActionID = gvAction.Rows[TheRow].Cells[1].Text;
            DataTable dtActionItems = dalOpportunityDetail.GetActionByID(ActionID);
            txtFUSummary.Text = dtActionItems.Rows[0]["Summary"].ToString();
            txtMemo.Text = dtActionItems.Rows[0]["Memo"].ToString();
            string type = dtActionItems.Rows[0]["Type"].ToString();

            if (dtActionItems.Rows[0]["isFollowupClosed"].ToString() == "-1")
            {

                rbFuOpen.Checked = true;
                rbFuClosed.Checked = false;
            }
            else
            {
                rbFuOpen.Checked = false;
                rbFuClosed.Checked = true;
            }
            pnFollowups.Visible = false;
            pnFollowupDetail.Visible = true;
        }



ASKER CERTIFIED SOLUTION
Avatar of thaytu888888
thaytu888888
Flag of Viet Nam image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial