Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7167203
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T14:32:24+00:00 2026-05-28T14:32:24+00:00

I have an asp.net page with c# code-behind. I have an event that is

  • 0

I have an asp.net page with c# code-behind. I have an event that is triggered in c# when the selected index on a gridview changes… This gridview is bound to an entites-data-source, and I need to find a way to tell my code-behind the id of the object that was selected when it calls the selected_index_changed() method. Any thoughts on how best to do this?

Current event handler code:

protected void VehiclesGridView_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (ChangeAttemptedId && !IsSavedId)
            {
                Alert.Show("Dispatch assignment saved... (But you forgot to click Confirm or Cancel!)");
            }
            IsSavedId = false;
            ChangeAttemptedId = true;
            int selectedIndex = VehiclesGridView.SelectedIndex + 1;
            getNextRide(selectedIndex); //TODO: FIX 
        }

ASP.NET Code:

<asp:EntityDataSource ID="VehiclesEDS" runat="server" EnableDelete="True" 
        EnableFlattening="False" EnableInsert="True" EnableUpdate="True" 
        EntitySetName="Vehicles" ContextTypeName="RamRideOps.RamRideOpsEntities" >
    </asp:EntityDataSource>

<asp:UpdatePanel ID="SelectCarUP" runat="server" UpdateMode="Conditional">
        <ContentTemplate>
            <asp:GridView ID="VehiclesGridView" runat="server" AllowPaging="True" 
                AllowSorting="True" DataSourceID="VehiclesEDS" AutoGenerateColumns="False" 
                onselectedindexchanged="VehiclesGridView_SelectedIndexChanged" 
                BackColor="White" BorderColor="#999999" BorderStyle="None" BorderWidth="1px" 
                CellPadding="3" GridLines="Vertical" ShowHeaderWhenEmpty="True" AutoPostBack="True">
                <AlternatingRowStyle BackColor="#DCDCDC" />
                <Columns>
                    <asp:TemplateField ShowHeader="False">
                        <ItemTemplate>
                            <asp:LinkButton ID="GVSelectButton" runat="server" CausesValidation="False" 
                                CommandName="Select" Text="Select"></asp:LinkButton>
                        </ItemTemplate>
                    </asp:TemplateField>
                    <asp:BoundField DataField="CarNum" HeaderText="Car" ReadOnly="True" 
                        SortExpression="CarNum" />
                    <asp:BoundField DataField="CurrPassengers" HeaderText="Passengers" 
                        ReadOnly="True" SortExpression="CurrPassengers" />
                    <asp:BoundField DataField="MaxPassengers" HeaderText="Capacity" ReadOnly="True" 
                        SortExpression="MaxPassengers" />
                    <asp:BoundField DataField="Status" HeaderText="Status" ReadOnly="True" 
                        SortExpression="Status" />
                    <asp:BoundField DataField="StartAdd" HeaderText="Pick-Up Address" 
                        ReadOnly="True" SortExpression="StartAdd" />
                    <asp:BoundField DataField="EndAdd" HeaderText="Drop-Off Address" 
                        ReadOnly="True" SortExpression="EndAdd" />
                    <asp:BoundField DataField="AvgRideTime" HeaderText="Avg. Ride Time" 
                        ReadOnly="True" SortExpression="AvgRideTime" />
                </Columns>
                <FooterStyle BackColor="#CCCCCC" ForeColor="Black" />
                <HeaderStyle BackColor="#004812" Font-Bold="True" ForeColor="White" />
                <PagerStyle BackColor="#999999" ForeColor="Black" HorizontalAlign="Center" />
                <RowStyle BackColor="#EEEEEE" ForeColor="Black" />
                <SelectedRowStyle BackColor="#C6940D" Font-Bold="True" ForeColor="White" />
                <SortedAscendingCellStyle BackColor="#F1F1F1" />
                <SortedAscendingHeaderStyle BackColor="#C6940D" />
                <SortedDescendingCellStyle BackColor="#CAC9C9" />
                <SortedDescendingHeaderStyle BackColor="#9F770B" />
            </asp:GridView>
        </ContentTemplate>
    </asp:UpdatePanel>

Error when changing EventArgs e to GridViewSelectEventArgs:

Compilation Error

Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately. 

Compiler Error Message: CS0123: No overload for 'VehiclesGridView_SelectedIndexChanged' matches delegate 'System.EventHandler'

Source Error:


Line 90:     <asp:UpdatePanel ID="SelectCarUP" runat="server" UpdateMode="Conditional">
Line 91:         <ContentTemplate>
Line 92:             <asp:GridView ID="VehiclesGridView" runat="server" AllowPaging="True" 
Line 93:                 AllowSorting="True" DataSourceID="VehiclesEDS" AutoGenerateColumns="False" 
Line 94:                 onselectedindexchanged="VehiclesGridView_SelectedIndexChanged" 
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T14:32:24+00:00Added an answer on May 28, 2026 at 2:32 pm

    If the parameter that you want to pass to getNextRide is indeed the same as selected index, then i’d make an event handler like this

        protected void VehiclesGridView_SelectedIndexChanged(object sender, GridViewSelectEventArgs e)
        {
            if (ChangeAttemptedId && !IsSavedId)
            {
                Alert.Show("Dispatch assignment saved... (But you forgot to click Confirm or Cancel!)");
            }
            IsSavedId = false;
            ChangeAttemptedId = true;
    
            int selectedIndex = e.NewSelectedIndex;
            getNextRide(selectedIndex); //TODO: FIX             
        }
    

    also, inside your event handler, you can access the individual members of your grid view like so: VehiclesGridView.Rows[e.NewSelectedIndex].Cells[i] where i is the index of your cell.

    Also, can you post the line where you set the datasource of VehiclesGridView, so that i might be able to come up with a cleaner answer

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In code-behind of an ASP.NET page I have this method: public string TestFunc() {
NET and VB.net code behind. I have a classic ASP page that connects to
I have an ASP.NET page with code-behind in VB.NET. On the ASPX page I
I have a normal asp.net page containing some code that I want to measure
I have an asp.net web page with a ton of code that is handled
I have some javascript on an asp.net page code behind, but whenever the page
I have an asp.net page. In the code behind I set a few private
I have the following code in my Site.Master page of an almost empty ASP.NET
I have a master page in my asp.net MVC project, which has code like
In The Page_Load event of an ASP.NET USercontrol, I have the following Code: If

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.