RadListView with buttons and ItemDataBound

3 posts, 1 answers
  1. Joe
    Joe avatar
    28 posts
    Member since:
    May 2007

    Posted 06 Dec 2009 Link to this post

    Hi!

    I'm using RadListView control that has two buttons with events inside as well as populating other
    information inside ItemDataBound event. However, I'm not getting arguments right and compile
    errors. What am I doing wrong?

    <telerik:RadListView PageSize="3"

     

    OnItemDataBound="lstRelatedItems_ItemDataBound" ID="lstRelatedItems"

     

     

    ItemPlaceholderID="ListViewContainer" DataKeyNames="ItemID" runat="server">

     

    <

     

    LayoutTemplate>

     

     

    <asp:PlaceHolder runat="server" id="ListViewContainer" />

     

     

    </LayoutTemplate>

     

     

    <ItemTemplate>

     

     

    <asp:ImageButton ID="btnAddToFavourites" OnCommand="AddToFavourites_Command" CommandArgument='<%# Eval("ItemID") %>' runat="server" /><br />

     

    <telerik:RadNumericTextBox ID="txtQuantity" Runat="server" Width="40px" CssClass="txt"

     

     

    DataType="System.Int16" MaxLength="5" MinValue="1" MaxValue="99999" ToolTip="quantity">

     

     

    <NumberFormat DecimalDigits="0" GroupSeparator="" />

     

     

    </telerik:RadNumericTextBox>

     

     

    <asp:ImageButton ID="btnAddToCart" OnCommand="AddToCart_Command" CommandArgument='<%# Eval("ItemID") %>' runat="server" />

     

     

    </div>

     

     

    </div>

     

     

    </fieldset>

     

     

    </ItemTemplate>

     

     

    </telerik:RadListView>

     



    protected

     

    void lstRelatedItems_ItemDataBound(object sender, RadListViewCommandEventArgs e)

     

    {

     

    ImageButton btnAddToFavourites = e.ListViewItem.FindControl("btnAddToFavourites") as ImageButton;

     

     

    ImageButton btnAddToCart = e.ListViewItem.FindControl("btnAddToCart") as ImageButton;

     

    btnAddToFavourites.ImageUrl =

    HttpContext.Current.Request.ApplicationPath + "\\images\\ATFButton.gif";

     

    btnAddToCart.ImageUrl =

    HttpContext.Current.Request.ApplicationPath + "\\images\\ATOButton.gif";

     

     

     

    RadListViewDataItem lvitem = (RadListViewDataItem)e.ListViewItem;

     

     

    Item item = ItemManager.GetByItemID(Convert.ToInt32(lvitem.GetDataKeyValue("ItemID")));

     

    }

     

    public

     

    void AddToFavourites_Command(Object sender, DataListCommandEventArgs e)

     

    {

     

    int itemID = Convert.ToInt32(e.CommandArgument);

     

     

    try

     

     

     

     

    {

     

    ShoppingCartManager.AddToCart(ShoppingCartTypeEnum.Favourites, itemID, 1);

     

    }

     

    catch (Exception ex)

     

    {

     

    }

    }

     

    public void AddToCart_Command(Object sender, DataListCommandEventArgs e)

     

    {

     

    TextBox txtQuantity = e.Item.FindControl("txtQuantity") as TextBox;

     

     

    int itemID = Convert.ToInt32(e.CommandArgument);

     

     

    if (txtQuantity.Text != string.Empty)

     

    {

     

    try

     

     

     

     

    {

     

    ShoppingCartManager.AddToCart(ShoppingCartTypeEnum.ShoppingCart, itemID, Convert.ToInt16(txtQuantity.Text));

     

    ((

    BaseOclMasterPage)Page.Master).LoadCart();

     

    ((

    BaseOclMasterPage)Page.Master).LoadViewCart();

     

     

    if (SettingManager.GetSettingValueBoolean("Display.StayOnSamePageWhenAddedToCart") == false)

     

    Response.Redirect(

    "~/ECommerce/ShoppingCart.aspx");

     

    }

     

    catch (Exception ex)

     

    {

    }

    }

    }

  2. Answer
    BaiH
    BaiH avatar
    83 posts
    Member since:
    Aug 2008

    Posted 07 Dec 2009 Link to this post

    Joe,

    Looking at the code you have pasted you have attached wrong event handler to the ImageButtons. Image button's click event handler  delegate does not use DataListCommandEventArgs in its signature.

    --BH
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Joe
    Joe avatar
    28 posts
    Member since:
    May 2007

    Posted 07 Dec 2009 Link to this post

    Thanks!!
Back to Top