Creating a DetailsView programatically

Discussion in 'ASP .Net' started by Fernando A. Gómez F., Nov 21, 2008.

  1. 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.
     
    Fernando A. Gómez F., Nov 21, 2008
    #1
    1. Advertising

  2. Fernando A. Gómez F.

    bruce barker Guest

    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:
    > 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, Nov 21, 2008
    #2
    1. Advertising

  3. bruce barker wrote:
    > 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.
     
    Fernando A. Gómez F., Nov 21, 2008
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Hrvoje Vrbanc
    Replies:
    1
    Views:
    471
  2. =?Utf-8?B?bWlrZQ==?=
    Replies:
    0
    Views:
    3,908
    =?Utf-8?B?bWlrZQ==?=
    Jul 20, 2006
  3. Big Daddy

    Creating a custom user control programatically

    Big Daddy, Nov 1, 2006, in forum: ASP .Net Building Controls
    Replies:
    2
    Views:
    129
    Big Daddy
    Nov 2, 2006
  4. Raja Rajan J

    Creating Datagrid Programatically

    Raja Rajan J, Jul 8, 2003, in forum: ASP .Net Datagrid Control
    Replies:
    0
    Views:
    138
    Raja Rajan J
    Jul 8, 2003
  5. Feege
    Replies:
    0
    Views:
    502
    Feege
    Dec 20, 2005
Loading...

Share This Page