Using jquery with EditItemTemplate of Datalist control
-
06-06-2021 - |
Pregunta
Is it possible to access controls inside EditItemTemplate of Datalist control using jquery. I have difficult time doing it, because "Edit" row is not rendered in html.
The only alternative I thanked of is not using DataList EditItemTemplate, but rather go only with jquery to hide and show rows and use ajax to update the contents of a row.
But, I would still want to hear option for EditItemTemplate and jquery.
Thanks
Solución
the html is rendered but only when you click on [Edit] see this post it shoud help you http://forums.asp.net/t/1668230.aspx/1
try this:
javascript:
<script type="text/javascript">
$(document).ready(function () {
showID();
});
function showID() {
if ($("[id*=QtyTextBox]").length)
alert($("[id*=QtyTextBox]").attr("id"));
}
</script>
EditItemTemplate:
<EditItemTemplate>
Quantity:
<asp:TextBox ID="QtyTextBox" Text='<%# DataBinder.Eval(Container.DataItem, "Qty") %>'
runat="server" />
<br />
<asp:LinkButton ID="UpdateButton" Text="Update" CommandName="Update"
runat="server" />
</EditItemTemplate>
Otros consejos
I followed your solution, but there is a problem. Now I am able to trigger an event, but the following code returns id as "undefined", despite the fact that it is declared inside datalist.
function bindPicker() {
$("input[type=text][id*=txtStartDate]").click(
function()
{
alert($(this).id);
});
}
I am not sure how to reference controls that triggered an event.