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 6921559
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T10:17:33+00:00 2026-05-27T10:17:33+00:00

I have a DetailsView bound to an EntityDataSource and am trying to get the

  • 0

I have a DetailsView bound to an EntityDataSource and am trying to get the values from my TextBoxes in the EditItemTemplates.

Here is my code:

 <asp:DetailsView ID="DetailsView1" DataKeyNames="Name" runat="server" AutoGenerateRows="False"
OnDataBound="DetailsView_DataBound" DataSourceID="eds2" BorderWidth="0"
OnModeChanging="OnModeChanging" AutoGenerateEditButton="true"
OnItemUpdated="DetailsView_OnItemUpdated" OnItemUpdating="DetailsView_OnItemUpdating"
EmptyDataText="N/A" OnDataBinding="DetailsView_OnDataBinding" CellPadding="0"
CellSpacing="7" GridLines="None" CssClass="Center">
<Fields>
<asp:TemplateField HeaderText="Name">
    <EditItemTemplate>
    <asp:TextBox ID="txtName" runat="server" Text='<%# Bind("Name") %>'></asp:TextBox>
    </EditItemTemplate>
    <ItemTemplate>
    <asp:Label ID="lblName" runat="server" Text='<%# Bind("Name") %>'></asp:Label>
    </ItemTemplate>
</asp:TemplateField>
 <Fields>
</asp:DetailsView>

And the code behind:

protected void OnModeChanging(object sender, DetailsViewModeEventArgs e)
{ 
    foreach (DetailsViewRow row in DetailsView1.Rows)
    {
        if (row.RowType != DataControlRowType.DataRow) continue;
        foreach (DataControlFieldCell cell in row.Cells)
        {
            var textbox = cell.FindControl("txtName");
            var textbox2 = row.FindControl("txtName");
        }
    }
}

textbox and textbox2 are always null. What am I doing wrong? How can I get either the textbox or the value inside it?

  • 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-27T10:17:34+00:00Added an answer on May 27, 2026 at 10:17 am

    You have these textboxes declared in your edit template. These will only show up when your mode has been set to edit. I’m guessing this hasn’t happened yet when the ModeChanging event is fired.

    Put your code in your ModeChanged event, and check to see that you’re editing.

    void DetailsView1_ModeChanged(object sender, EventArgs e)
    {
        if (DetailsView1.CurrentMode != DetailsViewMode.Edit)
            return;
    
        foreach (DetailsViewRow row in DetailsView1.Rows)
        {
           var textbox = row.FindControl("txtName");
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a DetailsView with a number of textboxes setup with RequiredFieldValidators. The code
I have a control that look something like this: <asp:DetailsView ID=dvUsers runat=server DataSourceID=odsData DataKeyNames=Id>
I have an asp.net page with a c# code-behind. I am trying to have
I have a DetailsView like this: <asp:DetailsView ID=detailsView1 runat=server DataSourceID=edsdetailsView AutoGenerateRows=False CssClass=pretty-table> <Fields> <asp:TemplateField
I currently have a DetailsView in ASP.NET that gets data from the database based
I have a DetailsView, I need get the value specifield in DataKeyNames UserId (a
I have my DetailsView bound to get data. It correctly returns 4 rows of
Am using VS2008 ASP.Net Web Forms have a detailsview, databound to web service reference
I have the following detailsview in my asp.net web application. What it should show
My problem is like this: In ASP DetailsView component we have three different EventArgs

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.