ASP.NET/SQL find the element ID and update database
Basically I've got an update query that runs when you click a submit button.
I have an asp:Repeater
in my page with a layer inside like this
<asp:Repeater id="dgBookings" runat="server" OnItemDataBound="ItemDB">
<itemtemplate>
<div class="bookingscontent">
<div class="bookingdetails" id="<%# DataBinder.Eval(Container.DataItem, "booking_ref") %>">
<p class="infotext"><%# DataBinder.Eval(Container.DataItem, "adults") %> <asp:LinkButton OnClick="EditDetails" Text="Edit..." runat="server"></asp:LinkButton></p>
<p class="infotext"><asp:LinkButton OnClick="SubmitDetails" Text="Submit..." runat="server"></asp:LinkButton></p>
</div>
</div>
</itemtemplate>
<asp:Repeater>
And it outputs HTML like this
<div class="bookingscontent">
<div class="bookingdetails" id="AL05720">
<p class="infotext">2</p>
<p class="infotext"> <a href="javascript:__doPostBack('dgBookings$ctl00$ctl08','')">Submit...</a></span> <a class="EditAdults" href="#" onclick="return false">Edit...</a></p>
</div>
</div>
<div class="bookingscontent">
<div class="bookingdetails" id="BD45670">
<p class="infotext">4</p>
<p class="infotext"> <a href="javascript:__doPostBack('dgBookings$ctl00$ctl08','')">Submit...</a></span> <a class="EditAdults" href="#" onclick="return false">Edit...</a></p>
</div>
</div>
Basically I need to get the ID of the div where the person has clicked submit and I can't figure out how.
I want to put that ID into a string or a session so it can be used in SubmitDetails
Sub
Any ideas
Thanks
Jamie
UPDATE
Here's is my Sub command how would I add the command name/command arguement into this?
Sub SubmitDetails(ByVal Sender as Object, ByVal e as EventArgs)
Dim strPassedText = CommandArgument
Dim LogData2 As sterm.markdata = New sterm.markdata()
Dim queryUpdate as String = ("UPDATE OPENQUERY (dev,'SELECT * FROM web_data WHERE booking_ref = ''"+ strPassedText +"'' ') SET c开发者_开发问答hildren = '1' ")
Dim drSetUpdate As DataSet = LogData2.StermQ2(queryUpdate)
Session("BookRefID") = strPassedText
LoadData()
End Sub
Thanks for the help so far
Jamie
Modify your repeater like this:
<asp:Repeater id="dgBookings" runat="server" OnItemDataBound="ItemDB" OnItemCommand="ItemCommand">
<itemtemplate>
<div class="bookingscontent">
<div class="bookingdetails" id="<%# DataBinder.Eval(Container.DataItem, "booking_ref") %>">
<p class="infotext"><%# DataBinder.Eval(Container.DataItem, "adults") %> <asp:LinkButton OnClick="EditDetails" Text="Edit..." runat="server"></asp:LinkButton></p>
<p class="infotext"><asp:LinkButton OnClick="SubmitDetails" Text="Submit..." runat="server" CommandName="SubmitDetails" CommandArgument="<%# DataBinder.Eval(Container.DataItem, "booking_ref") %>"></asp:LinkButton></p>
</div>
</div>
</itemtemplate>
<asp:Repeater>
I added a CommandArgument to your linkbutton. Then use the Item_Command event of the repeater to see the argument (in e.CommandArgument). Like this:
Sub SubmitDetails(ByVal Sender as Object, ByVal e as RepeaterCommandEventArgs)
Dim strPassedText = e.CommandArgument
Dim LogData2 As sterm.markdata = New sterm.markdata()
Dim queryUpdate as String = ("UPDATE OPENQUERY (dev,'SELECT * FROM web_data WHERE booking_ref = ''"+ strPassedText +"'' ') SET children = '1' ")
Dim drSetUpdate As DataSet = LogData2.StermQ2(queryUpdate)
Session("BookRefID") = strPassedText
LoadData()
End Sub
Add the "CommandName" and "CommandArgument" attributes to your Link Button with the ID you want (in this case, CoimmandArgument would be the same as the ID of your div and CommandName would be "Edit") You can then access the id in the Item_Command event by calling the property e.commandargument. Just make sure that you first check that e.CommandName is for the button you want, not something like the "Add" button.
精彩评论