Click here to Skip to main content
15,892,643 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
SQL
Sir, i have a Gridview in which i am using Gridview_SelectIndexChanged Method.In my gridview i have take in first COlumn an Imagebutton. i Need that when i click on Image button then SelectindexChanged not do there Work. and if i click on other Columns then its works fine.. My code is:-





XML
<asp:GridView ID="GridView3" runat="server" DataKeyNames="ClassesID" CssClass="mGrid"
    PagerStyle-CssClass="pgr" AlternatingRowStyle-CssClass="alt" AutoGenerateColumns="false"
    GridLines="Horizontal" OnRowDataBound="GridView3Bound" Width="100%">
    <Columns>

        <asp:TemplateField>
            <ItemTemplate>
                <asp:ImageButton ID="ImageButton2" runat="server" Style="cursor: pointer"  ImageUrl="~/images/plus.png" CommandName="Select" OnClick="Plus"/>
        </ItemTemplate>
        </asp:TemplateField>
        <asp:TemplateField HeaderText="Hostel" HeaderStyle-Width="350px">
            <HeaderTemplate>
                <span style="vertical-align: top">Class </span>
            </HeaderTemplate>
            <ItemTemplate>
                <asp:Label ID="lblhos" runat="server" Text='<%# Bind("Code") %>'></asp:Label>
            </ItemTemplate>
        </asp:TemplateField>
        <asp:BoundField DataField="P" HeaderText="Present" SortExpression="noofroom"
            HeaderStyle-Width="350px" HeaderStyle-HorizontalAlign="Right" ItemStyle-HorizontalAlign="Right" />
        <asp:BoundField DataField="a" HeaderText="Absent" SortExpression="full"
            HeaderStyle-Width="350px" HeaderStyle-HorizontalAlign="Right" ItemStyle-HorizontalAlign="Right" />
        <asp:BoundField DataField="per" HeaderText="%" SortExpression="Vacant"
            HeaderStyle-Width="350px" HeaderStyle-HorizontalAlign="Right" ItemStyle-HorizontalAlign="Right" />

        <asp:TemplateField ItemStyle-HorizontalAlign="Right" HeaderStyle-Width="50px" ItemStyle-Width="30px">
            <ItemTemplate>
                <asp:ImageButton ID="pri2" Width="30px" Height="30px" CommandName="Select"
                    CommandArgument='<%# Eval("ClassesID") %>' CausesValidation="False" ImageUrl="~/Images/printer.png"
                    runat="server" />
            </ItemTemplate>
        </asp:TemplateField>

        <asp:TemplateField Visible="false">
            <ItemTemplate>
                <asp:Label ID="ClassesID" runat="server" Visible="false" Text='<%# Bind("ClassesID") %>'></asp:Label>
            </ItemTemplate>
        </asp:TemplateField>

    </Columns>

</asp:GridView>



Vb Code:-

VB
Protected Sub GridView3_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles GridView3.SelectedIndexChanged
      

      
        Dim i As Integer = GridView3.SelectedIndex

        Dim DataKey As String = GridView3.DataKeys(GridView3.SelectedIndex).Value
        Session("ClassesID") = DataKey
    End Sub
Posted
Updated 29-Mar-15 22:21pm
v2

1 solution

you need to add RowCommand event and inside the event check for the command name. for example check below CP Tip

Example of gridview rowcommand on Button Click [^]
and MSDN Documentation on Row Command[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900