Solved

ASP.NET C# GridView Add Button

Posted on 2011-02-16
4
566 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
Comment Utility
       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
Comment Utility
0
 
LVL 11

Assisted Solution

by:SAMIR BHOGAYTA
SAMIR BHOGAYTA earned 167 total points
Comment Utility
0
 

Author Closing Comment

by:mawingho
Comment Utility
thanks
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

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 …
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

772 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

12 Experts available now in Live!

Get 1:1 Help Now