Solved

SelectedIndexChanged Event not firing when Select button Clicked

Posted on 2015-01-13
2
363 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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

713 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