Creating a DetailsView programatically

  • Thread starter Fernando A. Gómez F.
  • 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.
 
B

bruce barker

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

-- bruce (sqlwork.com)
 
F

Fernando A. Gómez F.

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,575
Members
45,054
Latest member
LucyCarper

Latest Threads

Top