Solved

SelectedIndexChanged Event not firing when Select button Clicked

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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

738 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