Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

grid view - link button click - get primary key

Posted on 2013-01-08
2
Medium Priority
?
988 Views
Last Modified: 2013-01-10
I've got a breakpoint on this method (see code snippet).

Execution stops on the breakpoint at runtime.

I've been looking at values for both sender and e  (passed into the method) and I cannot find the value I am looking for.

What I want is the value for "AgentFormListID" which is the primary key for each row.

I will include below the code snippet a screenshot describing what I want.  I'll also provide markup and code behind.


   protected void gvItems_RowEditing(object sender, GridViewEditEventArgs e)
        {

        }//breakpoint on this line

Open in new window




get pk


markup:
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="AgentFormAdd.ascx.cs"
    Inherits="Reo.ContentControls.AgentFormAdd" %>
<%@ Register Assembly="Framework" Namespace="Framework.UIControls" TagPrefix="cc1" %>
<div id="frame">
    <div id="frame_header">
        <div id="frame_title">
            <h1>
                Add New Agent Form</h1>
        </div>
    </div>

   <%-- <asp:UpdatePanel ID="UpdatePanelAgentFormAdd" runat="server" 
        ChildrenAsTriggers="False">
    <ContentTemplate>--%>
    <div id="corpus">
        <table class="layout_table">
            <tr>
                <td id="tdAMFirm" runat="server" visible="true">
                    <label>
                        AMFirm:</label><cc1:DdlGenericMerchant 
                        ID="ddlAMFirm" LookupCode="Mchnt_AMC" AllowUnassigned="true"
                            runat="server" >
                        </cc1:DdlGenericMerchant>
                </td>
                <td>
                    <label>
                        Client:</label><cc1:DdlGenericMerchant ID="ddlClient" LookupCode="Mchnt_Clnt" runat="server"
                            AutoPostBack="true">
                        </cc1:DdlGenericMerchant>
                </td>
                 <td>
                    <label>
                        Product:<asp:DropDownList ID="ddlProducts" runat="server"></asp:DropDownList>
                      
                     </label>
                </td>
                <td>
                    <asp:Button ID="ButtonShowAMFClientAgentForms" runat="server" Text="Show" 
                        onclick="ButtonShowAMFClientAgentForms_Click" />
                </td>
            </tr>          
            <tr>
                <asp:GridView ID="gvItems" runat="server" AutoGenerateColumns="false" AllowSorting="true"
                    AllowPaging="true" PageSize="100" CssClass="DataGrid"
                    HeaderStyle-CssClass="DataGrid_Header" RowStyle-CssClass="DataGrid_Row" 
                    Visible="true" DataKeyNames="AgentFormListID" onrowediting="gvItems_RowEditing">
                    <Columns>                         
                       <asp:TemplateField Visible="false">                                                    
                            <ItemTemplate>
                                <asp:Label ID="lblAgentFormListID" runat="server" Text='<%# Eval("AgentFormListID") %>' Font-Size="X-Small"></asp:Label>
                            </ItemTemplate>
                        </asp:TemplateField>    
                        <asp:TemplateField Visible="true">
                        <HeaderTemplate>Type</HeaderTemplate>
                            <ItemTemplate>
                                <asp:Label ID="lblFormTypeID" runat="server" Text='<%# Eval("FormTypeID") %>' Font-Size="X-Small"></asp:Label>
                            </ItemTemplate>
                        </asp:TemplateField> 
                        <asp:TemplateField Visible="true">
                        <HeaderTemplate>Name</HeaderTemplate>
                            <ItemTemplate>
                                <asp:Label ID="lblFormName" runat="server" Text='<%# Eval("FormName") %>' Font-Size="X-Small"></asp:Label>
                            </ItemTemplate>
                        </asp:TemplateField>                                            
                        <asp:TemplateField Visible="true">
                        <HeaderTemplate>Colist</HeaderTemplate>
                            <ItemTemplate>
                                <asp:Label ID="lblColistFlag" runat="server" Text='<%# Eval("ColistFlag") %>' Font-Size="X-Small"></asp:Label>
                            </ItemTemplate>
                        </asp:TemplateField>                                            
                        <asp:TemplateField Visible="true">
                        <HeaderTemplate>Acceptance Reqd</HeaderTemplate>
                            <ItemTemplate>
                                <asp:Label ID="lblAcceptanceReqd" runat="server" Text='<%# Eval("AcceptanceReqd") %>' Font-Size="X-Small"></asp:Label>
                            </ItemTemplate>
                        </asp:TemplateField>                                            
                        <asp:TemplateField Visible="true">
                        <HeaderTemplate>Duplicates Allowed</HeaderTemplate>
                            <ItemTemplate>
                                <asp:Label ID="lblDuplicatesAllowed" runat="server" Text='<%# Eval("DuplicatesAllowed") %>' Font-Size="X-Small"></asp:Label>
                            </ItemTemplate>
                        </asp:TemplateField>                                            
                        <asp:TemplateField Visible="true">
                        <HeaderTemplate>External Link</HeaderTemplate>
                            <ItemTemplate>
                                <asp:Label ID="lblExternalLink" runat="server" Text='<%# Eval("ExternalLink") %>' Font-Size="X-Small"></asp:Label>
                            </ItemTemplate>
                        </asp:TemplateField>                                            
                        <asp:TemplateField Visible="true">
                        <HeaderTemplate>Active</HeaderTemplate>
                            <ItemTemplate>
                                <asp:Label ID="lblActive" runat="server" Text='<%# Eval("Active") %>' Font-Size="X-Small"></asp:Label>
                            </ItemTemplate>
                        </asp:TemplateField>   
                         <asp:TemplateField Visible="true">
                         <ItemTemplate>
                            <asp:LinkButton runat="server" ID="LinkEdit" Enabled="true" CommandName="Edit" CommandArgument='<%# Eval("AgentFormListID") %>' >Edit</asp:LinkButton>
                         </ItemTemplate>
                        </asp:TemplateField>
                    </Columns>
                </asp:GridView>
            </tr>
        </table>
    </div>
 <%--   </ContentTemplate>
    </asp:UpdatePanel>--%>

    <div id="footer">
    </div>
</div>
<div id="end_cap">
</div>

Open in new window



code behind:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using System.IO;
using System.Data.Linq;
using System.Data;

using Models;
using Framework.Business;
using Framework.Utilities;
using System.Xml.Linq;
using Framework.UIControls.Base;
using System.Configuration;
using System.Text;
using System.Data.OleDb;
using System.Data.Common;
using System.Threading;

namespace Reo.ContentControls
{
    public partial class AgentFormAdd : Reo.Base.BaseControl
    {
        #region -- Members --
        protected User CurrentUser = Security.GetUserFromCache();
        DataTable Columns;
        StringBuilder errorMessage;
        List<AssetUpload_LoadResult> Loannumbers;
        List<string> LoadedLoannumbers = new List<string>();
        private bool IsPopupPost = false;
        protected List<ProductType_DropDown_GetResult> _ProductType;
        OleDbCommand command = null;
        DbDataReader dr = null;
        private User cuser = Security.GetUserFromCache();
        string path;
        protected List<Models.AgentFormAdd_AgentFormTypes_SelectResult> showamfclientagentforms;

        #endregion

        protected void Page_Load(object sender, EventArgs e)
        {
            FillProductTypeDDL();
           // ShowAMFClientAgentForms();
        }

        private void FillProductTypeDDL()
        {
            ProductTypeDataContext pdc = new ProductTypeDataContext();
            var result = pdc.ProductType_DropDown_Get(null, null, CurrentUser.UserID, CurrentUser.UserSID).ToList();
            this.ddlProducts.DataSource = result;
            ddlProducts.DataTextField = "Name";
            ddlProducts.DataValueField = "ProductTypeID";
            ddlProducts.DataBind();

         //   ddlProducts.Items.Insert(0, new ListItem("[Select]", "-1"));
        }

        private void ShowAMFClientAgentForms()
        {
            using (AgentFormsDataContext dc = new AgentFormsDataContext())
            {
                int tempamfid = Convert.ToInt32(ddlAMFirm.SelectedValue.Split('-')[0]);
                int tempclientid = Convert.ToInt32(ddlClient.SelectedValue.Split('-')[0]);
                int tempproductid = Convert.ToInt32(ddlProducts.SelectedValue.Split('-')[0]);

                showamfclientagentforms = dc.AgentFormAdd_AgentFormTypes_Select(tempamfid,tempclientid,tempproductid).ToList<AgentFormAdd_AgentFormTypes_SelectResult>();
                this.gvItems.DataSource = showamfclientagentforms;
                this.gvItems.DataBind();
            }
        }      

        protected void ButtonShowAMFClientAgentForms_Click(object sender, EventArgs e)
        {
            ShowAMFClientAgentForms();
        } 

        protected void gvItems_RowEditing(object sender, GridViewEditEventArgs e)
        {

        }

    }
}

Open in new window

0
Comment
Question by:Tom Knowlton
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 53

Accepted Solution

by:
Dhaest earned 2000 total points
ID: 38757961
Here I am explaining how to get the reference of the GridView Row and also the GridView Row Index when Button, ImageButton, or LinkButton is clicked or RowCommand Event is fired. In addition to that I will also explain how to add multiple CommandArguments to Control in GridView and retrieve the same.

Did you check it through the gridrow ?

protected void OnRowCommand(object sender, GridViewCommandEventArgs e)

{

    int index = Convert.ToInt32(e.CommandArgument);

    GridViewRow gvRow = GridView1.Rows[index];  
-- > now you can get the id in the gvrow ...

}


source = http://aspsnippets.com/Articles/ASP.Net-GridView---Get-Row-Index-on-RowCommand-and-Click-events.aspx
0
 
LVL 5

Author Comment

by:Tom Knowlton
ID: 38763692
Got this working.  It was OnRowCommand that I needed, as you suggested.
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

IP addresses can be stored in a database in any of several ways.  These ways may vary based on the volume of the data.  I was dealing with quite a large amount of data for user authentication purpose, and needed a way to minimize the storage.   …
It seems a simple enough task, yet I see repeated questions asking how to do it: how to pass data between two forms. In this article, I will show you the different mechanisms available for you to do just that. This article is directed towards the .N…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …

609 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