Wrox Home  
Search P2P Archive for: Go

  Return to Index  

aspdotnet_website_programming thread: Embedding VBScript inside a Datagrid template... is it possible?


Message #1 by "Ruairi" <ruairi@r...> on Fri, 26 Apr 2002 16:38:31 +0200
Is it possible to build dynamic templates for DataGrid or a DataList?  I
want to write a DataGrid that has columns that change depending on the
data type of the field.  I would prefer not to have to explicitly define
each column in the datgrid.

For example based on the column data type in a DataSet I want to create
an EditItemTemplate that does the following:


<asp:datagrid id="DGrid" runat="server" autogeneratecolumns="false"
DataSource="DS" ...>
<%col=DS.Tables[0].Columns[0]%>
<asp:TemplateColumn HeaderText="<%# col.ColumnName %>">
  <%If col.DataType =System.Type.GetType("System.String") then%>
	<EditItemTemplate>
		<asp:textbox id="<%# col.ColumnName %>" runat=server />
	</EditItemTemplate>
  <%else if col.DataType =System.Type.GetType("System.Boolean") then%>
	<EditItemTemplate>
		<asp:checkbox id="<%# col.ColumnName %>" runat=Server />
	</EditItemTemplate>
  <%end if%>
</asp:TemplateColumn>
</asp:datagrid>
Regards,
-Ruairi
____________________________________________________________


Message #2 by "Lewis Bass" <lewis@t...> on Fri, 26 Apr 2002 09:04:57 -0600
I ran into a similiar situation and ended up createing a seperate column for
each element and using the visible element

<edititemtemplate>
    <asp:texbox visible=<% display(container, "textbox") %>
id="tb1"></asp:textbox>
    <asp:dropdownlist visible=<% display(container, "dropdown") %>
id="dd1"></asp:textbox>
    <asp:checkbox visible=<% display(container, "dropdown") %>
id="dd1"></asp:checkbox>
</edititemtemplate>

then i wrote the display function in vb to check the type of field and
return a true or false as approprate

----- Original Message -----
From: "Ruairi" <ruairi@r...>
To: "Website Programming with ASP.NET"
<aspdotnet_website_programming@p...>
Sent: Friday, April 26, 2002 8:38 AM
Subject: [aspdotnet_website_programming] Embedding VBScript inside a
Datagrid template... is it possible?


> Is it possible to build dynamic templates for DataGrid or a DataList?  I
> want to write a DataGrid that has columns that change depending on the
> data type of the field.  I would prefer not to have to explicitly define
> each column in the datgrid.
>
> For example based on the column data type in a DataSet I want to create
> an EditItemTemplate that does the following:
>
>
> <asp:datagrid id="DGrid" runat="server" autogeneratecolumns="false"
> DataSource="DS" ...>
> <%col=DS.Tables[0].Columns[0]%>
> <asp:TemplateColumn HeaderText="<%# col.ColumnName %>">
>   <%If col.DataType =System.Type.GetType("System.String") then%>
> <EditItemTemplate>
> <asp:textbox id="<%# col.ColumnName %>" runat=server />
> </EditItemTemplate>
>   <%else if col.DataType =System.Type.GetType("System.Boolean") then%>
> <EditItemTemplate>
> <asp:checkbox id="<%# col.ColumnName %>" runat=Server />
> </EditItemTemplate>
>   <%end if%>
> </asp:TemplateColumn>
> </asp:datagrid>
> Regards,
> -Ruairi
> ____________________________________________________________
>
>
>
>


  Return to Index