Solved

SelectedIndexChanged Event not firing when Select button Clicked

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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

757 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

20 Experts available now in Live!

Get 1:1 Help Now