Solved

Gridview Button not firing on first click

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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…

830 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