I'm having a problem trying to get the value of the ID item that has been clicked in an asp.net Repeater. My Repeater has an image that opens a dialog, and from that dialog opened, when I click Approve, I would like to get this value in the .cs file when
I'm redirected because the ApproveChange_Click event. I'm not doing any DataBinder.Eval to the Id I want to retrieve in the Repeater, but I have it in the DataSet with which I fill it. How can I accomplish that? If I use session variables, where I can set
up the value in the .aspx page and how. Thanks in advance!
This is the Repeater:
<tr class="<%# Container.ItemIndex % 2 != 0 ? "" : "odd" %>">
<td class ="approval-img"><a class ="approvalDialog" href='#'><img src="/Images/Approve.png" alt ="Approve"/></td></a>
<td class ="approval-img"><a class ="declineDialog" href='#'><img src="/Images/Decline.png" alt ="Decline"/></td></a>
...
</tr>
Here is the solution that I have found: First: change the tag in the repeater for ImageButton, for have the chance to send a command argument to the event
jorge_sr
Member
4 Points
34 Posts
Get value of Id not displayed in the Repeater from a button event of a dialog
Dec 04, 2012 04:14 PM|LINK
I'm having a problem trying to get the value of the ID item that has been clicked in an asp.net Repeater. My Repeater has an image that opens a dialog, and from that dialog opened, when I click Approve, I would like to get this value in the .cs file when I'm redirected because the ApproveChange_Click event. I'm not doing any DataBinder.Eval to the Id I want to retrieve in the Repeater, but I have it in the DataSet with which I fill it. How can I accomplish that? If I use session variables, where I can set up the value in the .aspx page and how. Thanks in advance!
This is the Repeater:
<tr class="<%# Container.ItemIndex % 2 != 0 ? "" : "odd" %>"> <td class ="approval-img"><a class ="approvalDialog" href='#'><img src="/Images/Approve.png" alt ="Approve"/></td></a> <td class ="approval-img"><a class ="declineDialog" href='#'><img src="/Images/Decline.png" alt ="Decline"/></td></a> ... </tr>And this the dialog:
<div id="approval-form" style="display: none; cursor: default"> <div class="approve-change"> <ul> <li> <p><label>Reason</label></p> <textarea id="txtReason" runat="server" cols="1" rows="1" class="required"></textarea><br /> </li> <li> <span> <asp:Button ID="btnApprove" runat="server" CssClass="blue" Text="Approve" ToolTip = "Approve" OnClick="ApproveChange_Click" /> <button id="btnCancelApprove" class="blue">Cancel</button> </span> </li> </ul> </div> </div>jorge_sr
Member
4 Points
34 Posts
Re: Get value of Id not displayed in the Repeater from a button event of a dialog
Dec 05, 2012 10:40 AM|LINK
I could have the Id of the Items in the .cs by doing this in the Repeater:
<div id ="Hield" runat="server" visible="false"> <%# Eval("aux_approvalId")%> </div>And in the code behind:
foreach (RepeaterItem item in rptActiveChanges.Items) { System.Web.UI.HtmlControls.HtmlGenericControl hiddenContent2 = (System.Web.UI.HtmlControls.HtmlGenericControl)item.FindControl("Hield"); string ReportID = hiddenContent2.InnerHtml; }But now, how can I know which row has benn selected?
Frank Jiang ...
All-Star
16006 Points
1728 Posts
Microsoft
Re: Get value of Id not displayed in the Repeater from a button event of a dialog
Dec 06, 2012 07:14 AM|LINK
You can handle your Repeater ItemCommand event:
protected void Repeater1_ItemCommand(object source, RepeaterCommandEventArgs e) { System.Web.UI.HtmlControls.HtmlGenericControl hiddenContent2 = (System.Web.UI.HtmlControls.HtmlGenericControl)e.Item.FindControl("Hield"); string ReportID = hiddenContent2.InnerHtml; }now if you click on the image(that will fire the Repeater ItemCommand event) of Repeater, you will get the ReportID that you selected.
note: please replace <img> tag with ImageButton in the Repeater.
Feedback to us
Develop and promote your apps in Windows Store
jorge_sr
Member
4 Points
34 Posts
Re: Get value of Id not displayed in the Repeater from a button event of a dialog
Dec 06, 2012 08:33 AM|LINK
Hi Frank, I have this:
<td class ="approval-img"><asp:ImageButton class ="declineDialog" runat="server" CommandArgument = '<%# Eval("aux_approvalId")%>' OnClick="test_rr"/></td>and the repetear:
the class declineDialog do that an jQuery dialog opens, so if I write it, any of the two events (Repeater1_ItemCommand and test_rr) are firing.
jorge_sr
Member
4 Points
34 Posts
Re: Get value of Id not displayed in the Repeater from a button event of a dialog
Dec 07, 2012 03:03 PM|LINK
Here is the solution that I have found: First: change the tag in the repeater for ImageButton, for have the chance to send a command argument to the event
<td class ="approval-img"><asp:ImageButton runat="server" CommandArgument = '<%# Eval("aux_approvalId")%>' OnClick="getApprovalID_approve" ToolTip="Approve" ImageUrl="/Images/Approve.png" /></td>So, when I'm redirected to OnClick event, with this, I get the ID and after the dialog is opened.