Solved

SelectedIndexChanged Event not firing when Select button Clicked

Posted on 2015-01-13
2
343 Views
Last Modified: 2015-01-13
Good morning Experts!  Still trying to educate myself and having a hard time of it.  This is a ASP.NET Website Project (not a Web Application Project).  I have a GridView control on my content  page (within a master page).  When I click the "Select" button on a row I need to save the value in the "Id" column to a session variable so that I can use it elsewhere.  Unfortunately, the event that I thought would be best for this (SelectedIndexChanged) never fires when I click the "Select" button.  Any idea what I'm doing wrong?  Thanks!
    <asp:GridView ID="gvClientAccounts" runat="server" AllowPaging="True" AllowSorting="True" DataSourceID="dsClientAccounts" AutoGenerateColumns="False" OnSelectedIndexChanged="gvClientAccounts_SelectedIndexChanged">
        <Columns>
            <asp:TemplateField ShowHeader="True">
                <ItemTemplate>
                    <asp:HyperLink ID="lnkSelect" runat='server' NavigateUrl='<%# String.Format("~/Members/MyGroups.aspx?ClientID={0}", Eval("Id")) %>'>Select</asp:HyperLink>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:BoundField DataField="ClientName" HeaderText="Client Name" />
        </Columns>
    </asp:GridView><br />

Open in new window


    protected void gvClientAccounts_SelectedIndexChanged(object sender, EventArgs e)
    {
        Session["ClientID"] = gvClientAccounts.SelectedRow.Cells[0].Text;
    }

Open in new window


    <asp:GridView ID="gvClientAccounts" runat="server" AllowPaging="True" AllowSorting="True" DataSourceID="dsClientAccounts" AutoGenerateColumns="False" OnSelectedIndexChanged="gvClientAccounts_SelectedIndexChanged">
        <Columns>
            <asp:TemplateField ShowHeader="True">
                <ItemTemplate>
                    <asp:HyperLink ID="lnkSelect" runat='server' NavigateUrl='<%# String.Format("~/Members/MyGroups.aspx?ClientID={0}", Eval("Id")) %>'>Select</asp:HyperLink>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:BoundField DataField="ClientName" HeaderText="Client Name" />
        </Columns>
    </asp:GridView><br />

Open in new window

0
Comment
Question by:penlandt
2 Comments
 
LVL 23

Accepted Solution

by:
Michael74 earned 500 total points
ID: 40547901
I cannot see a select button for the control.
Add an auto generated select button and when selected this will fire your event


AutoGenerateSelectButton="True"
http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.gridview.autogenerateselectbutton(v=vs.110).aspx

<asp:GridView ID="gvClientAccounts" runat="server" AllowPaging="True" AllowSorting="True" DataSourceID="dsClientAccounts" AutoGenerateColumns="False" AutoGenerateSelectButton="True" OnSelectedIndexChanged="gvClientAccounts_SelectedIndexChanged">

Open in new window

0
 
LVL 1

Author Closing Comment

by:penlandt
ID: 40547987
Of course!  I'm overthinking this.  Did what you said and it works perfectly.  Thank you.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
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…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…

867 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