2011-04-27 108 views
0
<asp:ListView ID="ListView1" runat="server" DataSourceID="SqlDataSource1" 
      DataKeyNames="OfferID" GroupItemCount="2" > 

     <LayoutTemplate> 
      <table runat="server"> 
       <tr runat="server"> 
        <td runat="server"> 
         <table ID="groupPlaceholderContainer" runat="server" border="0" style=""> 
          <tr ID="groupPlaceholder" runat="server"> 
          </tr> 
         </table> 
        </td> 
       </tr> 
       <tr runat="server"> 
        <td runat="server" style=""> 
        </td> 
       </tr> 
      </table> 

     </LayoutTemplate> 

     <ItemTemplate> 
      <td runat="server" style=""> 

       <div id="wrapper"> 

     <div id="ResImage"> 


<div id="slideshow"> 

    <asp:Image ID="Image1" runat="server" ImageUrl='<%# Eval ("Image1") %>' Width="250px" Height="190px" CssClass="active" /> 
    <asp:Image ID="Image5" runat="server" ImageUrl='<%# Eval ("Image2") %>' Width="250px" Height="190px" /> 
    <asp:Image ID="Image4" runat="server" ImageUrl='<%# Eval ("Image3") %>' Width="250px" Height="190px" /> 


</div> 

     </div> 
     <div id="ResDesc"> 
      <asp:Label ID="lblDesc" runat="server" Width="290px" Height="190px" BackColor="White" Text='<%# Eval("Offer") %>'></asp:Label> 

     </div> 
     <div id="ResPrice1"> 
      <asp:Label ID="lblValue" runat="server" Text="Value" CssClass="ResValue"></asp:Label> 
      <asp:Label ID="lblDiscount" runat="server" Text="Discount" CssClass="ResDiscount"></asp:Label> 
      <asp:Label ID="lblYouPay" runat="server" Text="You Pay" CssClass="ResYouPay"></asp:Label> 
     <div id="ResPrice2"> 
      <asp:Label ID="lblValueAmt" runat="server" Text='<%# Eval("Value") %>' CssClass="ResValueAmt"></asp:Label> 
      <asp:Label ID="lblDiscountAmt" runat="server" Text='<%# Eval("Discount") %>' CssClass="ResDiscountAmt"></asp:Label> 
      <asp:Label ID="lblYouPayAmt" runat="server" Text='<%# Eval("YouPay") %>' CssClass="ResYouPayAmt"></asp:Label> 
     </div> 
      <asp:Label ID="lblRestaurantName" runat="server" Text='<%# Eval("RestaurantName") %>'></asp:Label><br /> 
      <asp:LinkButton ID="lnkGetCoupon" runat="server">Get Discount Coupon</asp:LinkButton> 
     </div> 

     <div id="HowItWorks"> 
      <asp:Label ID="lblHowItWorks" runat="server" Text="How It Works?" Font-Bold="True" Font-Size="Small" ForeColor="Red"></asp:Label> 
      <ul> 
      <li><asp:Label ID="Label3" runat="server" Text="1.Click on the 'Get Discount Coupon' button" Font-Size="10px"></asp:Label></li> 
      <li><asp:Label ID="Label4" runat="server" Text="2.Get a print of your Voucher and carry it during your visit to the outlet." Font-Size="10px"></asp:Label></li> 
      <li><asp:Label ID="Label5" runat="server" Text="3.Show your Voucher and pay the amount directly to the merchant. " Font-Size="10px"></asp:Label></li> 
      </ul> 
     </div> 

     <asp:Label ID="OfferID" runat="server" Text='<%# Eval("OfferID") %>' Visible="false"></asp:Label> 
     </div> 
      </td> 
     </ItemTemplate> 

如何找到id = OfferID的标签控件...如何在这里使用findcontrol? 我想找到我点击的行的OfferID ...我有一个linkbutton lnkGetCoupon..when我点击链接按钮...我想要将查询字符串中的OfferID传递到下一页。如何找到控件OfferID?

我是一个新用户,使他们不要让我回答后,以我自己的问题

继承人的答案...

我加入CommandArgument='<%# Eval("OfferID") %>的链接按钮。

<asp:LinkButton ID="lnkGetCoupon" CommandArgument='<%# Eval("OfferID") %>' runat="server">Get Discount Coupon</asp:LinkButton> 

和使用ListView1_ItemCommand

Protected Sub ListView1_ItemCommand(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.ListViewCommandEventArgs) Handles ListView1.ItemCommand 
     Dim offer As String 
     offer = e.CommandArgument.ToString() 
     Dim url As String = "~/RestaurantDedicatedPage.aspx?offerID=" + offer 
     Response.Redirect(url, True) 
    End Sub 
+0

在什么时候,在的DataBind? – Craig 2011-04-27 22:11:48

+0

你需要使用FindControl吗?您已在DataKeyNames集合中获得了OfferID。 – Town 2011-04-27 22:12:55

回答

0

你不需要Label可言,你可以从DataKeys收集得到OFFERID 。

首先,CommandName的添加到您的LinkBut​​ton:

<asp:LinkButton ID="lnkGetCoupon" runat="server" CommandName="GetCoupon">Get Discount Coupon</asp:LinkButton> 

在ItemCommand处理程序,然后使用它:

protected void ListView1_ItemCommand(object sender, ListViewCommandEventArgs e) 
{ 
    if (e.CommandName == "GetCoupon") 
    { 
     ListViewDataItem item = (ListViewDataItem)e.Item; 
     int index = item.DataItemIndex; 
     string offerID = ((ListView)sender).DataKeys[index]["OfferID"].ToString(); 

     Response.Redirect("yourUrl" + offerID); 
    } 
} 
+0

http://stackoverflow.com/questions/5782665/how-do-i-use-a-photo-slide-show-inside-listview请检查这篇文章?? – Monodeep 2011-04-27 23:10:02

+0

@Monodeep:是否以任何方式与此问题相关? – Town 2011-04-27 23:13:53

+0

nope..thats jthery和列表视图 – Monodeep 2011-04-27 23:23:35

0

连接到ListView.ItemCommand事件,该事件中,你可以在ListViewCommandEventArgsItem搜索找到你需要改变控制。

在你的ASPX更新您的ListView挂钩的ItemCommand事件:

<asp:ListView ... OnItemDataBound="ListView1_ItemCommand"> 
    <ItemTemplate> 
     ... 
     <asp:LinkButton id="lnkGetCoupon" CommandName="View" CommandArgument="<%# Eval("OfferID") %>" /> 
     ... 
    </ItemTemplate> 
</asp:ListView> 

点击一个按钮或LinkButton(或其他一些按钮式的控制)时,ItemCommand事件将被解雇。要处理此事件,以下 代码添加到您的* .aspx.cs(代码隐藏)文件:

protected void ListView1_ItemDataBound(object sender, ListViewCommandEventArgs e) 
{ 
    //Check if the lnkGetCoupon button was clicked. 
    if (string.Equals("View", e.CommandName)) 
    { 
     //Get the offerID from the CommandArgument. 
     int offerID = int.Parse(e.CommandArgument); 

     //Perform your logic using the offerID 
    } 
} 
+0

请解释...我对asp.net非常陌生。 – Monodeep 2011-04-27 22:12:39

+0

我想找到我点击的行的OfferID ...我有一个linkbutton'lnkGetCoupon'..when我点击链接按钮...我想要在查询字符串中传递OfferID。 – Monodeep 2011-04-27 22:22:21

+0

好的,这是不同的 - 我会更新我的答案。 – 2011-04-27 22:35:05