asp.net function : receives value from one of the database field that acts as an max value for a listbox. useful when ordering quantity needs to be restricted to available quantity.
----ASP.NET ----
<asp:TemplateField HeaderText="Select">
<ItemTemplate>
<asp:ListBox ID="ListBox1" SelectionMode="Single" Rows="1" runat="server" DataSource='<%# ddlItems((string)(Eval("QtyLeft").ToString())) %>'>asp:ListBox>
ItemTemplate>
<ItemStyle HorizontalAlign="Center" />
asp:TemplateField>
protected ListItemCollection ddlItems(String max)
{
ListItem li = null;
ListItemCollection liC = new ListItemCollection();
int intmax = Convert.ToInt32(max);
for (int i = 0; i <= intmax; i++)
{
li = new ListItem();
li.Text = ""+ i;
liC.Add(li);
li = null;
}
return liC;
}
No comments:
Post a Comment