ASP.NET / SQL查找元素ID并更新数据库

时间:2010-10-12 16:01:10

标签: asp.net sql

基本上我有一个更新查询,当你点击提交按钮时会运行。

我的页面中有一个asp:Repeater,里面有一个像这样的

<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>

它会像这样输出HTML

<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>

基本上我需要获取该人点击提交的div的ID,我无法弄清楚如何。

我想将该ID放入字符串或会话中,以便可以在SubmitDetails Sub

中使用

任何想法

由于

杰米

更新

这是我的Sub命令如何将命令name / command arguement添加到此?

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 children = '1' ")

Dim drSetUpdate As DataSet = LogData2.StermQ2(queryUpdate)

Session("BookRefID") = strPassedText

LoadData()

End Sub

感谢目前为止提供的帮助

杰米

2 个答案:

答案 0 :(得分:4)

像这样修改你的转发器:

<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>

我在你的linkbutton中添加了一个CommandArgument。然后使用转发器的Item_Command事件来查看参数(在e.CommandArgument中)。像这样:

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

答案 1 :(得分:2)

将“CommandName”和“CommandArgument”属性添加到您想要的ID的链接按钮(在这种情况下,CoimmandArgument将与您的div的ID相同,CommandName将是“编辑”)您可以访问通过调用属性e.commandargument在Item_Command事件中的id。只需确保首先检查e.CommandName是否适用于您想要的按钮,而不是“添加”按钮。