Vimal Patel
Vimal Patel

Reputation: 3055

gridview SelectedIndexChanged Event is not firing.I am using asp.net 4.0 .By the way rowdatabound event is firing perfectly

 <asp:GridView ID="gridPlace" runat="server" AutoGenerateColumns="False" Width="800px"
        BackColor="White" BorderColor="#CCCCCC" BorderStyle="None" BorderWidth="1px"
        CellPadding="5" OnRowDataBound="gridPlace_RowDataBound" OnSelectedIndexChanged="gridPlace_SelectedIndexChanged">
        <Columns>
            <asp:BoundField HeaderText="DetailID" DataField="PID" />
            <asp:BoundField HeaderText="Name" DataField="Name" ControlStyle-Width="200px" />
            <asp:BoundField HeaderText="Description" DataField="Description" />
            <asp:TemplateField>
                <ItemTemplate>
                    <asp:ImageButton ID="btnEdit" runat="server" ImageUrl="~/Images/Edit.png" ToolTip="Click To Edit this Record" />
                </ItemTemplate>
                <ItemStyle Width="40px" HorizontalAlign="Center" />
            </asp:TemplateField>
        </Columns>
        <EmptyDataTemplate>
            <h2 class="CustomErrorMsg">
            No Record Found</h3>
        </EmptyDataTemplate>
    </asp:GridView>

Here is my html markup for the gridview.RowDatabound event is firing perfectly.Kindly Help

Upvotes: 0

Views: 6837

Answers (2)

gaijintendo
gaijintendo

Reputation: 423

I have had these symptoms using TemplateFields.

TemplateFields allow you to have items in different columns with the same ID - without intellisense highlighting an error.

Under those circumstances, two links with the same ID can prevent the click being resolved.

Ususally this will be a copy and paste error.

Hope this helps someone!

Upvotes: 0

codingbiz
codingbiz

Reputation: 26386

You cannot just click anywhere on a row to fire the event, you will need JavaScript to do that. Think these would help

  1. <asp:GridView Runat="server" ID="GridView1" AutoGenerateSelectButton="true" /> - How to: Enable Default Selection in the GridView Web Server Control

  2. Add

    <asp:TemplateField> <ItemTemplate> <asp:LinkButton CommandName="Select" /> </ItemTemplate> </asp:TemplateField>

  3. Use JavaScript if you don't want the select button to appear - http://forums.asp.net/t/992062.aspx/1

  4. <asp:CommandField ShowSelectButton="true" ButtonType="Image" /> - http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.commandfield.aspx

Upvotes: 1

Related Questions