Click here to Skip to main content
15,896,063 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all,
I need to find out which of the columns in the gridview was clicked.
I know you can do this for row easily.. but what do you do if you need to find out which of teh colulmns was clicked?

Thanks.
Posted

 
Share this answer
 
use link button or button in the gridview row.
Here i am giving an example of using link button.
XML
<asp:GridView ID="grdDoc" runat="server" AllowPaging="True"
            AutoGenerateColumns="False" DataKeyNames="DOCCODE" Height="40px"
            PageSize="8" ShowFooter="True"   Visible="false"
            onpageindexchanging="grdDoc_PageIndexChanging"
            onselectedindexchanged="grdDoc_SelectedIndexChanged" >       <PagerSettings Mode="NumericFirstLast" />
            <RowStyle BackColor="WhiteSmoke" BorderColor="CornflowerBlue" ForeColor="Black"Height="30px" /> <Columns><asp:TemplateField HeaderText="Dose">
   <ItemTemplate> <asp:LinkButton ID="LinkButton1" runat="server" CommandName="select"Text='<%#Eval("DOCCODE")%>'></asp:LinkButton>                  </ItemTemplate>
                </asp:TemplateField>
                <asp:BoundField DataField="DOCNAME" HeaderText="Description" />
            </Columns>
            <FooterStyle BackColor="Silver" Height="25px" />
            <PagerStyle BackColor="DarkGray" />
            <HeaderStyle BackColor="#000084" Font-Bold="True" ForeColor="White" />
        </asp:GridView>



In gridview SelectedIndexChanged event
write ur code

C#
protected void grdDoc_SelectedIndexChanged(object sender, EventArgs e)
       {
           txtDocCode.Text = Convert.ToString(grdDoc.SelectedDataKey.Value);
           txtDocName.Text = Convert.ToString(grdDoc.SelectedRow.Cells[1].Text);
           grdDoc.Visible = false;
       }
 
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