Answered by:
Get Listview item with Linkbutton

Question
-
User1228272764 posted
i have this listview :
<div class="form-group"> <div class="col-sm-8" style="margin-bottom:4%;margin-top:1%"> <asp:SqlDataSource ID="SqlPelamarBaru" runat="server" ConnectionString="<%$ ConnectionStrings:MugenKarirConnection %>" SelectCommand="select Id_lamaran, User_nama, User_Posisi from Data_Lamaran " ProviderName="<%$ ConnectionStrings:MugenKarirConnection.ProviderName %>"> </asp:SqlDataSource> <asp:ListView ID="LvPelamarBaru" runat="server" DataSourceID="SqlPelamarBaru" DataKeyNames ="Id_lamaran" enableviewstate="false" > <LayoutTemplate> <table class="table table-bordered striped data" align="left"> <thead> <th style="text-align:center; color:red; background-color:#a9a9a9">Check</th> <th style="text-align:center; color:red; background-color:#a9a9a9">ID Lamaran</th> <th style="text-align:center; color:red; background-color:#a9a9a9">Nama Pelamar</th> <th style="text-align:center; color:red; background-color:#a9a9a9">Posisi</th> <th style="text-align:center; color:red; background-color:#a9a9a9">Download Certificate</th> <th style="text-align:center; color:red; background-color:#a9a9a9">Download ID Card</th> <th style="text-align:center; color:red; background-color:#a9a9a9">Download Resume</th> </thead> <asp:PlaceHolder ID="itemPlaceHolder" runat="server" /> </table> </LayoutTemplate> <ItemTemplate> <tr> <td> <asp:CheckBox ID="CheckBoxListIDPel" runat="server" value='<%# Eval("Id_Lamaran") %>' /> </td> <td><%#Eval("Id_Lamaran")%> </td> <td><%#Eval("User_nama")%></td> <td><%#Eval("User_posisi")%></td> <td> <asp:LinkButton ID="LinkButton1" runat="server">Download Certificate</asp:LinkButton> </td> <td> <asp:LinkButton ID="LinkButton2" runat="server">Download ID Card</asp:LinkButton> </td> <td> <asp:LinkButton ID="LinkButton3" runat="server">Download Resume</asp:LinkButton> </td> </tr> </ItemTemplate> </asp:ListView> </div> </div>
i have 3 coloumns that contains different link button. Each one should automaticaly download the related file based on DataKeyNames ="Id_lamaran", but i have no idea how to start to get related datakey by each button?
the main goal, user can perform specific download for specific file on specific record based on link button in each row
does any one have a clue ?
Thursday, March 21, 2019 9:18 AM
Answers
-
User2103319870 posted
but i have no idea how to start to get related datakey by each button?First subscribe to Click event of button
<asp:LinkButton ID="LinkButton1" runat="server" OnClick="LinkButton1_Click">Download Certificate</asp:LinkButton>
Now you can access data keys like below
protected void LinkButton1_Click(object sender, EventArgs e) { var button = sender as LinkButton; // Get the selected listview item ListViewItem item = button.NamingContainer as ListViewItem; // Get the datakey from listview // Change the listview id and datakey name here string DataKeyvalue = LvPelamarBaru.DataKeys[item.DataItemIndex].Values["Id_lamaran"].ToString(); }
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Thursday, March 21, 2019 3:10 PM
All replies
-
User2103319870 posted
but i have no idea how to start to get related datakey by each button?First subscribe to Click event of button
<asp:LinkButton ID="LinkButton1" runat="server" OnClick="LinkButton1_Click">Download Certificate</asp:LinkButton>
Now you can access data keys like below
protected void LinkButton1_Click(object sender, EventArgs e) { var button = sender as LinkButton; // Get the selected listview item ListViewItem item = button.NamingContainer as ListViewItem; // Get the datakey from listview // Change the listview id and datakey name here string DataKeyvalue = LvPelamarBaru.DataKeys[item.DataItemIndex].Values["Id_lamaran"].ToString(); }
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Thursday, March 21, 2019 3:10 PM -
User1228272764 posted
Awesome ! it's work :) thank you so much
Friday, March 22, 2019 3:50 AM