Creating a DetailsView programatically

  • Thread starter Thread starter Fernando A. Gómez F.
  • Start date Start date
F

Fernando A. Gómez F.

Hello all.

I'm building a WebControl. In it's CreateChildControls, I'm creating a
DataSource and a DetailsView controls and set de DV's DataSourceID to
the control I just created.

Now, I'm not sure how to add the template fields and then bind them. I
mean, I'm lookin the translation from this:

<asp:DetailsView ID="CatalogDetailView" runat="server" ...etc... >
<Fields>
<asp:TemplateField HeaderText="Aplicación *"
HeaderStyle-HorizontalAlign="Left"
ItemStyle-HorizontalAlign="left" >
<InsertItemTemplate>
<asp:DropDownList ID="ddlAplicacion" runat="server"
Width="205px" DataSourceID="AplicacionCatDataSource"
DataValueField="ClaveAplicacion"
DataTextField="NombreAplicacion"
SelectedValue='<%# Bind("IdAplicacion") %>' <------here
AutoPostBack="true" />
</InsertItemTemplate>
<EditItemTemplate >
...etc...
</EditItemTemplate>
</asp:TemplateField>
</Fields>
</asp:DetailsView>

Into C# code. I mean, in the ASP.NET page I just use the <%# Bind(...)
%> tag and be done with it. How do I translate that into C# code? How
can I bind the control?

Any help will be appreciated. Thanks in advance

Regards,
Fernando.
 
binding expression are converted code when the aspx is compiled. when
you create dropdown, after the databind, just set the selectedValue.

-- bruce (sqlwork.com)
 
bruce said:
binding expression are converted code when the aspx is compiled. when
you create dropdown, after the databind, just set the selectedValue.

-- bruce (sqlwork.com)

Hello Bruce,

thanks for the answer. Do you mean that I'd have to subscribe to the
DataSource's DataBind event and manually set the SelectedValue?

Thanks.
 
Back
Top