0

我想在viewdatesbutton.jpg单击时添加 TID 的值,以便可以将其传递到另一个网页。

我怎样才能做到这一点?

代码:

<asp:repeater id="Repeater1" datasourceid="SqlDataSource1" runat="server">

<itemtemplate>

<div class="content-1g">
    <div class="content-1-1g">
        </div>
    <div class="content-1-2g"><p class="none"><%# Eval("TName")%></p><p><span style="color:#FFFFFF"><%# Eval("TDetails")%></span></p>
        <div class="content-1-2ag">
            <div class="content-1-3g">Duration: <%# Eval("TDuration")%> </div>
            <div class="content-1-3g">Adult: £<%# Eval("TPriceadult")%> </div>
            <div class="content-1-3g">Senior/Student: £<%# Eval("TPricesenior")%> </div>
            <div class="content-1-3g">Child: £<%# Eval("TPricechild")%> </div>
        </div>
        <div class="content-1-2bg"><img alt="" src="/images/viewdatesbutton.jpg" />
        </div>
    </div>
</div>

    <div class="line"><hr class="top" /></div>

</itemtemplate>

</asp:repeater>

    <asp:sqldatasource id="SqlDataSource1"  runat="server" 
        ConnectionString="<%$ ConnectionStrings:ChinatowndbConnString %>" 
        SelectCommand="SELECT TID, TName, TDetails, TDuration, TPriceadult, TPricesenior, TPricechild FROM [Tour] WHERE TEventCategory=2">
 </asp:sqldatasource>

我假设我可以在点击按钮时拥有一个功能?如何在其上传递 TID 的值?

问候,茶

编辑:

        <asp:LinkButton ID="lbYear" runat="server" CausesValidation="false" OnCommand="redirectnewpage" CommandArgument='<%#Eval("TourId")%>'>
            <asp:Image ID="imgFolder" runat="server" ImageUrl="/images/viewdatesbutton.jpg" />
        </asp:LinkButton>


protected void redirectnewpage(object sender, CommandEventArgs e)
{
    Response.Redirect("book.aspx?tourid="+ e.CommandArgument.ToString());
}
4

4 回答 4

1

您可以使用<asp:ImageButton>服务器端控制和使用CommandArgument它的属性:

<div class="content-1-2bg">
    <asp:ImageButton runat="server" 
         ImageUrl="/images/viewdatesbutton.jpg" 
         CommandArgument='<%# Eval("TID") %>' 
         OnCommand="ImgButton_OnCommand" />

</div>

然后在事件处理程序中获取TID值:OnCommand

private void ImgButton_OnCommand(object sender, CommandEventArgs e)
{
    var tid = int.Parse(e.CommandArgument.ToString());
}
于 2012-11-29T16:25:47.097 回答
0

您可以将 ImageButton 添加到模板中,并使用CommandArgument插入 TID。例如:

<asp:ImageButton ImageUrl="~/icon.png" ID="TIDButton" runat="server"  
                 CommandArgument=<%# Eval("TID") %> OnClick="TIDButton_Click" />

然后,将其放入您的代码中:

    protected void TIDButton_Click(object sender, EventArgs e)
    {
        ImageButton b = sender as ImageButton;
        if (b == null)
          return; 

        string TID = b.CommandArgument;
    }
于 2012-11-29T16:26:19.463 回答
0
<asp:LinkButton ID="lbYear" runat="server" CausesValidation="false" OnCommand="redirectnewpage" CommandArgument='<%#Eval("TourId")%>'>
            <asp:Image ID="imgFolder" runat="server" ImageUrl="/images/viewdatesbutton.jpg" />
        </asp:LinkButton>


protected void redirectnewpage(object sender, CommandEventArgs e)
{
    Response.Redirect("book.aspx?tourid="+ e.CommandArgument.ToString());
于 2012-11-29T16:30:52.343 回答
0
    <asp:LinkButton ID="lbYear" runat="server" CausesValidation="false" OnCommand="redirectnewpage" CommandArgument='<%#"tourId="+Eval("TourId").ToString()+"&TID="+Eval("TID").ToString()%>'>
        <asp:Image ID="imgFolder" runat="server" ImageUrl="/images/viewdatesbutton.jpg" />
    </asp:LinkButton>


protected void redirectnewpage(object sender, CommandEventArgs e)
{
   Response.Redirect("book?"+ e.CommandArgument.ToString());
}
于 2012-11-29T16:33:53.423 回答