Given a positive integer k and a graph G = (V, E), a function f from V to the power set ofis the set of all neighbors of vertex v and I k = {1, . . . , k}. Finding a k-rainbow function of minimum weight of P v2V |f (v)|, which is called the k-rainbow domination problem, is known to be NP-complete for arbitrary graphs and values of k. In this paper, we propose a dynamic programming algorithm to solve the k-rainbow domination problem for graphs with bounded treewidth tw in O ⇣ 2 k+1 + 1 tw n ⌘time, where G has n vertices. Moreover, we also show that the same approach is applicable to solve the weighted k-rainbow domination problem with the same complexity. Therefore, both problems of k-rainbow and weighted k-rainbow domination belong to the class FPT, or fixed parameter tractable, with respect to tree-width. In addition to formally showing the correctness of our algorithms, we also implemented these algorithms to illustrate some examples.