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 6346353
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T21:00:01+00:00 2026-05-24T21:00:01+00:00

I have added new event i.e Gridview_Onclick event dynamically in RowDatabound event. But when

  • 0

I have added new event i.e Gridview_Onclick event dynamically in RowDatabound event. But when I try to handle that event in the server side code, I can code for that event. This is the code for my grid view.

<%@ Control Language="C#" AutoEventWireup="true" CodeFile="PopUp.ascx.cs" Inherits="PopUp" %>
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>

<table class="style1">
<tr>
    <td>
        <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" 
            CellPadding="4" ForeColor="#333333" GridLines="None" 
            onrowdatabound="GridView1_RowDataBound">
            <AlternatingRowStyle BackColor="White" ForeColor="#284775" />
            <Columns>
                <asp:BoundField DataField="DeptId" HeaderText="ID"/>
                <asp:BoundField DataField="Name" HeaderText="Name"/>
                <asp:BoundField DataField="HeadName" HeaderText="HOD"/>
                <asp:BoundField DataField="HeadEmail" HeaderText="Email ID"/>
            </Columns>
            <EditRowStyle BackColor="#999999" />
            <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
            <HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
            <PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
            <RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
            <SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
            <SortedAscendingCellStyle BackColor="#E9E7E2" />
            <SortedAscendingHeaderStyle BackColor="#506C8C" />
            <SortedDescendingCellStyle BackColor="#FFFDF8" />
            <SortedDescendingHeaderStyle BackColor="#6F8DAE" />
        </asp:GridView>
        <asp:Button ID="btnTest" runat="server" style="display:none" />
    </td>
</tr> 
</table>

This is the code for my ascs.cs page

protected void Page_Load(object sender, EventArgs e)
{
    oCommand.CommandText = "select * from Department";
    oCommand.Connection = oConnection;
    oAdapter.SelectCommand = oCommand;
    DataTable dt = new DataTable();
    oAdapter.Fill(dt);
    GridView1.DataSource = dt;
    GridView1.DataBind();
}
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
    e.Row.Attributes["OnClick"] = Page.ClientScript.GetPostBackClientHyperlink(e.Row, string.Empty);
}
protected void GridView1_OnClick(object sender, GridViewRowEventArgs e)
{
    _ID = "10";
    _Name = "abc";
    _HOD = "abc";
    _Email = "abc";
}

The grid view opens in modelpopupextender so when I click anywhere in grid, its getting closed which is not the case of I remove the event that is added dynamically. In short the event is added but can not be handled in code.
Please guide me how can I catch this event in coding??

  • 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-24T21:00:03+00:00Added an answer on May 24, 2026 at 9:00 pm

    You need to do following changes at your code:
    1)

     e.Row.Attributes["OnClick"] = Page.ClientScript.GetPostBackClientHyperlink(**btnTest**, string.Empty);
    

    2)

     protected void GridView1_OnClick(object sender, **EventArgs** e)
    

    3) <asp:Button ID="btnTest" runat="server" Style="display: none" **OnClick="GridView1_OnClick"** />

    Why?

    The reason is GridViewRow doesn’t implement IPostBackEventHandler, therefore doesn”t fire postback events. But button can. At this case btnTest it is dummy button for event firing.

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

Sidebar

Related Questions

I have added a new job in my hudson server which builds the project
I have added an image for my button,but when I run that frame this
I have an events form that allows someone to add a new event. An
In Application_Start event in global.asax.cs, I have added some initialization code. This code is
I JUST started a new XCode Project. The code I have added in so
I have added the following code for displaying a scrollbar to my textfield. But
i have added this code iTunes.OnPlayerPlayingTrackChangedEvent += new _IiTunesEvents_OnPlayerPlayingTrackChangedEventEventHandler(iTunes_OnPlayerPlayingTrackChangedEvent); and this code private void
I have a small winforms app that creates a new event log source. I
Most of my content is in a new table I have added to JOOMLA
I have a list within Sharepoint, using a custom new form I have added

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.