This is a migrated thread and some comments may be shown as answers.

RadListView with buttons and ItemDataBound

2 Answers 658 Views
ListView
This is a migrated thread and some comments may be shown as answers.
Joe
Top achievements
Rank 1
Joe asked on 07 Dec 2009, 05:37 AM
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 Answers, 1 is accepted

Sort by
0
Accepted
BaiH
Top achievements
Rank 1
answered on 07 Dec 2009, 04:01 PM
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
0
Joe
Top achievements
Rank 1
answered on 08 Dec 2009, 05:56 AM
Thanks!!
Tags
ListView
Asked by
Joe
Top achievements
Rank 1
Answers by
BaiH
Top achievements
Rank 1
Joe
Top achievements
Rank 1
Share this question
or