I am having an issue by link one table to another. I am getting data from database and showing it on griedview and made it hyperlink now how can I get the Id of the value which is selected? Thanx
Thanx Mahede for your guidance but the problem is my information is showing in gridview in the form of hyperlink and I want to get id of each hyperlink value when it is clicked.
ayubjaved
0 Points
9 Posts
How to get id by clicking hyperlink in gridview
Apr 29, 2012 12:07 AM|LINK
I am having an issue by link one table to another. I am getting data from database and showing it on griedview and made it hyperlink now how can I get the Id of the value which is selected? Thanx
mahedee
Member
450 Points
116 Posts
Re: How to get id by clicking hyperlink in gridview
Apr 29, 2012 12:30 AM|LINK
Suppose you have a grid view like this.
<asp:GridView ID="gvEmpInfo" runat="server" AutoGenerateColumns="False" CellPadding="4" ForeColor="#333333" GridLines="None"> <AlternatingRowStyle BackColor="White" /> <Columns> <asp:BoundField DataField="emp_fullnm" HeaderText="Full Name" /> <asp:BoundField DataField="emp_nicknm" HeaderText="Nick Name" /> <asp:BoundField DataField="emp_designation" HeaderText="Designation" /> <asp:TemplateField HeaderText="Edit"> <ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" Width="80px" /> <ItemTemplate> <asp:HiddenField ID="hidemp_gid" runat="server" Value='<%#Eval("emp_gid") %>' /> <asp:LinkButton ID="btnEdit" Text="Edit" runat="server" CausesValidation="false" RowIndex='<%# Container.DisplayIndex %>' OnClick="btnEdit_Click"> <img style="border:none;" src = "Images/edit_icon.gif"/>asp:LinkButton> ItemTemplate> asp:TemplateField> <asp:TemplateField HeaderText="Delete"> <ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" Width="80px" /> <ItemTemplate> <asp:LinkButton ID="btnDelete" Text="Delete" runat="server" CausesValidation="false" RowIndex='<%# Container.DisplayIndex %>' OnClick="btnDelete_Click"> <img style="border:none;" src = "Images/icon_remove.png"/>asp:LinkButton> ItemTemplate> asp:TemplateField> Columns> <EditRowStyle BackColor="#2461BF" /> <FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" /> <HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" /> <PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" /> <RowStyle BackColor="#EFF3FB" /> <SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" /> <SortedAscendingCellStyle BackColor="#F5F7FB" /> <SortedAscendingHeaderStyle BackColor="#6D95E1" /> <SortedDescendingCellStyle BackColor="#E9EBEF" /> <SortedDescendingHeaderStyle BackColor="#4870BE" /> asp:GridView>Then get the id of selected that is clicked row by following way.
protected void btnDelete_Click(object sender, EventArgs e) { LinkButton btnDelete = sender as LinkButton; //Identify the clicked row int rowIndex = Convert.ToInt32(btnDelete.Attributes["RowIndex"]); }For details please vist the link - http://mahedee.blogspot.com/2012/04/simple-demonstration-with-aspnet.html
If this post helped you, please marked it as answer.
Mahedee
Blog: http://mahedee.blogspot.com
ayubjaved
0 Points
9 Posts
Re: How to get id by clicking hyperlink in gridview
Apr 29, 2012 08:58 AM|LINK
Thanx Mahede for your guidance but the problem is my information is showing in gridview in the form of hyperlink and I want to get id of each hyperlink value when it is clicked.
asp.netC#