Solved

Gridview Button not firing on first click

Posted on 2010-08-19
1
231 Views
Last Modified: 2012-06-21
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;
        }



0
Comment
Question by:daforga
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 6

Accepted Solution

by:
thaytu888888 earned 500 total points
ID: 33477239
- Why you need this line of code:  btn.ID = RowCount.ToString(); ?
- Please post Page_Load function so i can have more informations.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.

751 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question