Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6663835
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T02:32:35+00:00 2026-05-26T02:32:35+00:00

I want to set a value (Field IDCommerciale) when I click the insert button

  • 0

I want to set a value (Field IDCommerciale) when I click the insert button on a details view. I tried to change the value using OnItemInserting but nothing happens.
This is the code on the aspx:

 <asp:DetailsView ID="DetailsView1" runat="server" Height="50px" Width="125px" DefaultMode="Insert"
                AutoGenerateRows="False" DataKeyNames="IDPianificazione"
                DataSourceID="EntityDataSourceDetailsView" OnItemInserting="insertingmodeevent"
                >
                <Fields>
                    <asp:TemplateField HeaderText="IDCommerciale"
                        SortExpression="IDCommerciale">
                        <ItemTemplate>
                            <asp:Label ID="Label1" runat="server" Text='<%# Bind("Commerciali.Nome") %>'></asp:Label>
                        </ItemTemplate>
                        <InsertItemTemplate>
                        <asp:DropDownList ID="ddlIDCommerciale" runat="server" SelectedValue='<%# Bind("IDCommerciale") %>'
                            DataSourceID="EntityDataSource1" DataTextField="Nome"
                            DataValueField='IDCommerciale'>                        
                        </asp:DropDownList>
                        </InsertItemTemplate>
                    </asp:TemplateField>
                    <asp:TemplateField HeaderText="IDCLiente" SortExpression="IDCLiente">
                        <ItemTemplate>
                            <asp:Label ID="Label2" runat="server" Text='<%# Bind("IDCLiente") %>'></asp:Label>
                        </ItemTemplate>
                        <InsertItemTemplate>
                            <asp:TextBox ID="TextBox2" runat="server" Text='<%# Bind("IDCLiente") %>'></asp:TextBox>
                        </InsertItemTemplate>
                    </asp:TemplateField>
                    <asp:TemplateField HeaderText="IDCategoria" SortExpression="IDCategoria">
                        <ItemTemplate>
                            <asp:Label ID="Label3" runat="server" Text='<%# Bind("IDCategoria") %>'></asp:Label>
                        </ItemTemplate>
                        <InsertItemTemplate>
                            <asp:TextBox ID="TextBox3" runat="server" Text='<%# Bind("IDCategoria") %>'></asp:TextBox>
                        </InsertItemTemplate>
                    </asp:TemplateField>
                    <asp:BoundField DataField="Oggetto" HeaderText="Oggetto" 
                        SortExpression="Oggetto" />
                    <asp:BoundField DataField="datainizio" HeaderText="datainizio" 
                        SortExpression="datainizio" />
                    <asp:BoundField DataField="DataPresuntaFine" HeaderText="DataPresuntaFine" 
                        SortExpression="DataPresuntaFine" />
                    <asp:BoundField DataField="DataCompletamento" HeaderText="DataCompletamento" 
                        SortExpression="DataCompletamento" />
                    <asp:CommandField 
                        ShowInsertButton="True" />
                </Fields>
            </asp:DetailsView>




            <asp:EntityDataSource ID="EntityDataSourceDetailsView" runat="server" 
                ConnectionString="name=SalesPortalEntities" Include="Categorie,Commerciali,Clienti"
                DefaultContainerName="SalesPortalEntities" EnableDelete="True" 
                EnableFlattening="False" EnableInsert="True" EnableUpdate="True" 
                EntitySetName="PianificazioneIncontri">
            </asp:EntityDataSource>

        <asp:EntityDataSource ID="EntityDataSource1" runat="server" 
            ConnectionString="name=SalesPortalEntities" 
            DefaultContainerName="SalesPortalEntities" EnableFlattening="False" 
            EntitySetName="Commerciali">
        </asp:EntityDataSource>

and this is the code behind:

protected void insertingmodeevent(object sender, EventArgs e)
    {
        string gruppoAdmin = System.Web.Security.FormsAuthentication.Decrypt(Request.Cookies[1].Value).UserData;
        if (gruppoAdmin.Contains("SPGAdmins"))
        {
            try
            {
            DropDownList dd = new DropDownList();
            dd = DetailsView1.FindControl("ddlIDCommerciale") as DropDownList;
            dd.SelectedIndex = 1;
            dd.SelectedValue = "1";
            }
            catch (Exception)
            {

                new Exception();
            }


        }
        else
        {
          // other code
        }
    }

The code is execude regularly but if I check the data on the Database, the Item does’ent take the value forced on the code behind. I tried also with The event OnDataBinding but the result is the same.
How can I force the value for this field?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T02:32:36+00:00Added an answer on May 26, 2026 at 2:32 am

    A possible solution is to add an event OnItemInserting on the entitydatasource of my gridview. Then I used this code:

    protected void UpdateDataSource(object sender, EntityDataSourceChangingEventArgs e)
    {
        if (!gruppoAdmin.Contains("SPGAdmins"))
        {
            SalesPortalModel.PianificazioneIncontri pianificazione = e.Entity as SalesPortalModel.PianificazioneIncontri;
            int idCommerciale = (from a in entity.Commerciali where a.Nome == Context.User.Identity.Name select a.IDCommerciale).First();
            pianificazione.IDCommerciale = idCommerciale;
            detailsView1.Rows[1].Visible = false;
        }
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to set the value of a private field using reflection for unit
I want to set the value of a hidden field, using JQuery. Hidden Field:
i want to set the default value in a sql server 2005 datetime field
I have a usecase where I want to set the value of a field
I am using gwt uibinder. I want to dynamically set values to a field.
I know I'm over thinking this, but I want to check a single value/field
I want to set the default value of my forms 'author' field (models.ForeignKey(User)) to
.NET I want to clone a value type's fields. How can i set a
I want to set my GtkComboBox to have some default value/name, on it as
I have a textbox whose value I want to set based on the inner

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.