Solved

Gridview Button not firing on first click

Posted on 2010-08-19
1
227 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
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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

746 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now