Excellent reference site!
The reason why someone would need to create a DG (or DL) on the fly is that
they may need to
use variables to change things like the headers. The inability to use
code-behind variables inside server controls - the
single greatest handicap of ASP.NET - can be overcome by building your
literals from variables via
dynamic DG creation.
For example, say you wanted to do the following:
<asp:HyperLink id="HyperLink1" runat="server" NavigateUrl='<%#
"../index.aspx?catID=" & currentCat & "|" &
DataBinder.Eval(Container.DataItem, "CategoryID")%>' Text='<%#
DataBinder.Eval(Container.DataItem, "CategoryName") %>'></asp:HyperLink>
where currentCat was some variable declared in a code behind.
It is impossible to do because you cannot use variables from a code-behind
in a server control (i.e. 'currentCat' would never contain a value no matter
where it was declared). The only workaround is to dynamically create your
control.