Connecting Tech Pros Worldwide Forums | Help | Site Map

Creating a DetailsView programatically

=?ISO-8859-1?Q?=22Fernando_A=2E_G=F3mez_F=2E=22?=
Guest
 
Posts: n/a
#1: Nov 21 '08
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.

bruce barker
Guest
 
Posts: n/a
#2: Nov 21 '08

re: Creating a DetailsView programatically


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

-- bruce (sqlwork.com)

Fernando A. Gómez F. wrote:
Quote:
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.
=?ISO-8859-1?Q?=22Fernando_A=2E_G=F3mez_F=2E=22?=
Guest
 
Posts: n/a
#3: Nov 21 '08

re: Creating a DetailsView programatically


bruce barker wrote:
Quote:
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.
Closed Thread