The APS.Net DataList    Sample at:  ../Datalist/AspDatalist.aspx

 

The DataList Video

 

 

 

<EditItemTemplate>

          Note on the line below how I set the TEXT of the TextBox txtName to vName…

            <asp:TextBox id=txtName runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "vName") %>'></asp:TextBox><BR>>

            <asp:Button id="Button1" runat="server" Text="Button"></asp:Button>

            <asp:Button id="Button2" runat="server" Text="Button"></asp:Button>

            <sp:Button id="Button3" runat="server" Text="Delete" CommandName = "delete"></asp:Button>        

</EditItemTemplate>

 

 

 

<ItemTemplate>

     <asp:DropDownList id="ddlNames" runat="server" DataSource='<%#GetDropDownDataTable() %>' DataTextField="vName" DataValueField="vName" />

</ItemTemplate>

 

Here’s the function that loads the DropDownList’s Values…

    Function GetDropDownDataTable()

        '***********'********** Create A Table ***********************************

        Dim dt As New DataTable()

        Dim dr As DataRow

 

        dt.Columns.Add(New DataColumn("vAge", GetType(Int32)))

        dt.Columns.Add(New DataColumn("vName", GetType(String)))

 

        Dim i As Integer

        For i = 0 To 8

            dr = dt.NewRow()

            dr("vAge") = i

            dr("vName") = "My Name " & i.ToString()

            dt.Rows.Add(dr)

        Next i

        '**************************************************************************

        Return dt

    End Function

 

This code checks the Dropdown list Selected Item…

    Private Sub cmdDDL_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdDDL.Click

        Dim i As Integer

        Dim DDL As DropDownList

 

        For i = 0 To DataList1.Items.Count - 1

            DDL = DataList1.Items(i).FindControl("ddlNames")

            Response.Write("DropDownList.text = " & DDL.SelectedItem.ToString)

        Next

 

    End Sub

 

 

The code below runs when the “Check The Radio Buttons” Command Button is pressed…

    Private Sub cmdCheckRadio_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles           cmdCheckRadio.Click

     

        Dim i As Integer

        Dim R1 As RadioButton

        Dim R2 As RadioButton

        ‘Loop Through all the DataList’s Items,(Items are really just Rows).

        For i = 0 To DataList1.Items.Count - 1

            R1 = DataList1.Items(i).FindControl("RadioButton1")

            R2 = DataList1.Items(i).FindControl("RadioButton2")

            If R1.Checked Then

                Response.Write("Radio Button 1 Checked At Item " & i & "<br>")

            End If

            If R2.Checked Then

                Response.Write("Radio Button 2 Checked At Item " & i & "<br>")

            End If

        Next

 

    End Sub

 

This is how to modify a template cell at runtime…

Private Sub DataGrid1_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs) Handles DataGrid1.ItemDataBound

      If e.Item.ItemType = ListItemType.Item Or e.Item.ItemType = ListItemType.AlternatingItem Then
            CType
(e.Item.FindControl("TextBox1"), TextBox).Text = Val(e.Item.Cells(1).Text) * 10
      End If

End Sub

How To Format A Date In A DataList…

 

<asp:TextBox id=txtCheckDate runat="server" Text='<%# format("{0:d}",DataBinder.Eval(Container.DataItem, "Check_Date"))         %>'></asp:TextBox>

 

OR

 

<asp:TextBox id=txtCheckDate runat="server" Text='<%# MyDateFormat(DataBinder.Eval(Container.DataItem, "Check_Date")) %>'>

 

    Public Function MyDateFormat(ByVal vO As Object)

        If IsDBNull(vO) Then

            Return (" ")

        Else

            Return (Format("{0:d}", vO))

        End If

 

   End Function