• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 575
  • Last Modified:

ASP.NET C# GridView Add Button

I have added a button in the EditTemplate.
<asp:TemplateField HeaderText="Work Plan">
                        <asp:Label ID="lblJobNameCY" runat="server" Text='<%# Eval("JOB_NAME_CY") %>'></asp:Label>

                        <asp:DropDownList ID="ddlJobIDCY" runat="server" Text='<%# Bind("JOB_ID_CY") %>' CssClass="workPlanDropDownList"></asp:DropDownList><br />
                        <asp:Label>All</asp:Label><asp:CheckBox ID="cbxUpdateAllJobIDCY" runat="server" />
                        <asp:Button ID="btnAddJob" runat="server" Text="Add" OnClick="btnAddJob_Click"/>

Open in new window

So it will call the function when user click it
protected void btnAddJob_Click(object sender, EventArgs e)
            bool hasError = false;
            string three_year_work_plan_status_id = "";
            string type = "";

            string selectedCompanyID = ((Label)GridView1.Rows[e.RowIndex].FindControl("lblCompanyID")).Text;
            string selectedDivisionID = "";
            string selectedSubDivisionID = "";

Open in new window

However, why I can't change the argument to
protected void btnAddJob_Click(object sender, GridViewUpdateEventArgs e)
so I can easily to use the variable e to access the current editing row in the GridView

anyone can help? It doesn't work....
3 Solutions
       protected void btnAddJob_Click(object sender, EventArgs e)
            Button Button1 = (Button)sender;
            GridViewRow gvRow = (GridViewRow)Button1.Parent.Parent;
           // either use the gridview row directly or take the index gvRow.RowIndex

good luck
SAMIR BHOGAYTAFreelancer and IT ConsultantCommented:
mawinghoAuthor Commented:
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now