asp:listbox and selected value within a repeater

J

John Giblin

I have a ListBox within a repeater tag and I am trying to set the selected
value. I tried the following without success. I was also trying to make a
method for the selectedindex but I do not know how to pass the instance of
this asp:listbox control.

<asp:ListBox id="ListBox1" name="ListBox1" DataSource='<%#
GetDropDownQuantities( (BasketLine)DataBinder.Eval(Container,"DataItem"))
%>'
Rows="1"
CssClass="orderselect"
SelectionMode=Single
runat="server">
</asp:ListBox>


public ListItemCollection GetDropDownQuantities( BasketLine bl)
{
ListItemCollection listBoxData = new ListItemCollection();

int x=0;
bool isSelected = false;
while (x++ < 20)
{
ListItem li = new ListItem();
li.Value = x.ToString();
li.Text = x.ToString();
if (x==bl.Quantity && !isSelected)
{
li.Selected = true;
isSelected = true;
}
listBoxData.Add(li);

}
return listBoxData;
}

thanks

John
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,020
Latest member
GenesisGai

Latest Threads

Top