Solved

ASP.NET C# GridView Add Button

Posted on 2011-02-16
4
569 Views
Last Modified: 2012-05-11
I have added a button in the EditTemplate.
 
<asp:TemplateField HeaderText="Work Plan">
                    <ItemTemplate>
                        <asp:Label ID="lblJobNameCY" runat="server" Text='<%# Eval("JOB_NAME_CY") %>'></asp:Label>
                    </ItemTemplate>

                    <EditItemTemplate>
                        <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"/>
                    </EditItemTemplate>
                </asp:TemplateField>

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....
0
Comment
Question by:mawingho
4 Comments
 
LVL 11

Accepted Solution

by:
MajorBigDeal earned 167 total points
ID: 34913841
       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
0
 
LVL 7

Assisted Solution

by:kovilpattiBalu
kovilpattiBalu earned 166 total points
ID: 34913967
0
 
LVL 11

Assisted Solution

by:SAMIR BHOGAYTA
SAMIR BHOGAYTA earned 167 total points
ID: 34914173
0
 

Author Closing Comment

by:mawingho
ID: 34923991
thanks
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

Suggested Solutions

Title # Comments Views Activity
jquery datatables, asp.net MVC 9 51
edit .asp files 5 31
How to verify that an email address ends with a particular set of characters in C#? 2 27
Name Space error VS2015 1 25
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
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…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

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