WEB DEVELOPER SITE
HTMLCSSJAVASCRIPTSQLPHPBOOTSTRAPJQUERYANGULARXML
 

ASP.NET Web Forms - Data Binding


Create an ArrayList

The ArrayList object is a gathering of things containing a solitary information value.

Items are added to the ArrayList with the Add() method.

The following code makes another ArrayList object named mycountries and four things are added:

<script runat="server">
Sub Page_Load
if Not Page.IsPostBack then
  diminish mycountries=New ArrayList
  mycountries.Add("Norway")
  mycountries.Add("Sweden")
  mycountries.Add("France")
  mycountries.Add("Italy")
end if
end sub
</script>

By default, an ArrayList object contains 16 passages. An ArrayList can be measured to its last size with the TrimToSize() method:

<script runat="server">
Sub Page_Load
if Not Page.IsPostBack then
  diminish mycountries=New ArrayList
  mycountries.Add("Norway")
  mycountries.Add("Sweden")
  mycountries.Add("France")
  mycountries.Add("Italy")
  mycountries.TrimToSize()
end if
end sub
</script>

An ArrayList can likewise be arranged in order or numerically with the Sort() method:

<script runat="server">
Sub Page_Load
if Not Page.IsPostBack then
  diminish mycountries=New ArrayList
  mycountries.Add("Norway")
  mycountries.Add("Sweden")
  mycountries.Add("France")
  mycountries.Add("Italy")
  mycountries.TrimToSize()
  mycountries.Sort()
end if
end sub
</script>

To sort backward request, apply the Reverse() technique after the Sort() method:

<script runat="server">
Sub Page_Load
if Not Page.IsPostBack then
  diminish mycountries=New ArrayList
  mycountries.Add("Norway")
  mycountries.Add("Sweden")
  mycountries.Add("France")
  mycountries.Add("Italy")
  mycountries.TrimToSize()
  mycountries.Sort()
  mycountries.Reverse()
end if
end sub
</script>

Data Binding to an ArrayList

An ArrayList article may consequently produce the content and qualities to the accompanying controls:

  • asp:RadioButtonList
  • asp:CheckBoxList
  • asp:DropDownList
  • asp:Listbox

To tie information to a RadioButtonList control, first make a RadioButtonList control (without any asp:ListItem components) in an .aspx page:

<html>
<body>

<form runat="server">
<asp:RadioButtonList id="rb" runat="server"/>
</form>

</body>
</html>

Then include the content that constructs the rundown and ties the qualities in the rundown to the RadioButtonList control:

Example

<script runat="server">
Sub Page_Load
if Not Page.IsPostBack then
  dim mycountries=New ArrayList
  mycountries.Add("Norway")
  mycountries.Add("Sweden")
  mycountries.Add("France")
  mycountries.Add("Italy")
  mycountries.TrimToSize()
  mycountries.Sort()
  rb.DataSource=mycountries
  rb.DataBind()
end if
end sub
</script>

<html>
<body>

<form runat="server">
<asp:RadioButtonList id="rb" runat="server"/>
</form>

</body>
</html>
Show precedent »

The DataSource property of the RadioButtonList control is set to the ArrayList and it characterizes the information wellspring of the RadioButtonList control. The DataBind() strategy for the RadioButtonList control ties the information source with the RadioButtonList control.