.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
david stephan
Gaurav Pal
Post New Web Links

FindControl In DetailsView Edit & Insert ItemTemplate

Posted By:      Posted Date: October 11, 2010    Points: 0   Category :ASP.Net

Hey,guys. I got a problem about finding controls in Edit/Insert Itemtemplate inside a DetailsView.

Here is the code.

I put a Label (id= "Label6") to test whether the findcontrol method works or not. Unfortunately, I almost tried every means but still coudn't find it.

protected void Page_Load(object sender, EventArgs e)

  //Edit Button OnCommand
  protected void ButtonEditOnCommand(object sender, CommandEventArgs e)
  if (e.CommandName == "Edit")

  // Update Button OnCommand
  protected void ButtonUpdateOnCommand(object sender, CommandEventArgs e)
  if (e.CommandName == "Update")
  string sql = "UPDATE StudentInfo SET StudentName=@studentname, Score=@score, Grade=@grade, Remarks=@remarks WHERE ID=@id";
  SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["sqlconn"].ToString());
  SqlCommand cmd = new SqlCommand(sql, conn);

  // find controls
  if (DetailsView1.CurrentMode == DetailsViewMode.Edit)
  TextBox EditStudentName = (TextBox)DetailsView1.FindControl("TextBoxEditStudentName");
  TextBox EditScore = (TextBox)DetailsView1.FindControl("TextBoxEditScore");
  TextBox EditGrade

View Complete Post

More Related Resource Links

Detecting Edit or Insert Page


I am coding a .cs file that handles the metadata for a particular table. I am putting a custom validation that allows me to update or insert only if the PubMedID is not already in the database. This would be easy except that the PMID should also be allowed to be null as some of the references in the database were not from PubMed. So i perform a query on the database to see if there is already an identical PMID in the database. This works great when using Insert. However, when using Edit, it does not. The PMID is already in the database because the one currently being edited has the same PMID!!! So I know exactly how to change my query etc. However, I do not know how to tell from inside this Edit/Insert agnostic page, which one it is being called from. Thanks for your help! 

review, edit and insert data using 2 diffrent database



is it possible to create a custom list in sharepoint designer to enter a vacation request and using a work flow that goes to the HR department. but when the HR department approve the request the HR can store these requested data into another database?

what i mean is, the employee fill a form in to request some vacation days using a custom list in my wss3 site. i assume that these data will be stored in the WSS_content database. now when the HR department get this filled form they have to store the data of the form in to a database but not in the WSS_Content database.

is this possible?

Customizing the Insert/Edit Forms

Hi, I need to have 2 tables show in one webform(one-to-one relationship). I have tried customizing the Insert webform from the PageTemplates(creating the entity folder under CustomPages and copying the Insert page from PageTemplates), but it shows a lot of duplicate errors, e.g. The type GRIPS.Insert already contains a definition for DynamicDatamanager1, ScriptManagerProxy, etc... Can anyone tell me what I'm doing wrong? Thanks, CC

Insert and Edit Pages with Web User Control Template for another table

Hi, I have an Address template(web user control) which holds the fields of the Address table.  The Address template is embedded in the School Insert Page.  I want to insert a new school together with its address(which means I have to insert a record into the address table).  Can you let me know how I can pass the newly generated addressId to update school table?  Also, how can I associate the Address.cs in the App_Code with the Address template?  I want it to be able to scaffold columns which needs to be hidden from user in the address table.  When I click on Insert School, the Address template shows in "insert" mode, I just need to link the two together. Thanks for your help! CC  

Detailsview edit not saving

Hello! I would like to edit a record in detailsview and it's not working. After I click "edit" it show the view in edit mode and if I change anything and click save no error is returned; just detailsview in "read/only mode", but without changes. This is the aspx code: <asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">     <h2>         Urejanje kontaktnih podatkov     </h2>     <p>         <asp:TextBox ID="txtKontaktID" Visible="false" runat="server"></asp:TextBox>         <asp:SqlDataSource ID="SqlDataSource1" runat="server"              ConnectionString="<%$ ConnectionStrings:testConnectionString %>"              ProviderName="<%$ ConnectionStrings:testConnectionString.ProviderName %>"              SelectCommand="SELECT tblKontakt.*, tblStranka.strSkrajsanNaziv FROM tblKontakt INNER JOIN tblStranka ON tblKontakt.StrankaID = tblStranka.StrankaID                        

Custom Insert / Edit Pages

I'm working with a legacy database that is not normalized, nor can i change it to normalize it and/or add relationships. I've successfully got my List and Details pages up and running and am now moving on to insert/edit. Here's my challenge: The insert page needs to accept data that will be written to multiple tables (i.e. consider a customer call where we're creating the customer, the customer address record, etc. on the fly). In addition, the customer can either be a "customer" or a "prospect", each being a separate table. Any suggestions as the best approach to tackling this issue. My gut feel is that I should write a standard aspx page and hook up the data manually. Not sure how to navigate to this page from the insert / edit button (modified routing). Thanks.

DetailsView get key after insert

Hello!I'm trying to catch (in string "s") the primary key for the record being inserted via DetailsView. I have an SqlDataSource connection to an Access 2003 database. The primary key is auto-increment integer (long) field.Code:protected void SqlDataSource1_Inserting(object sender, SqlDataSourceCommandEventArgs e) { OleDbParameter insertedKey = new OleDbParameter("@KontaktID", OleDbType.Integer); insertedKey.Direction = ParameterDirection.Output; e.Command.Parameters.Add(insertedKey); } protected void SqlDataSource1_Inserted(object sender, SqlDataSourceStatusEventArgs e) { DbCommand command = e.Command; string s = command.Parameters["@KontaktID"].Value.ToString(); }generates an error:System.Data.OleDb.OleDbDataAdapter internal error: invalid parameter accessor: 12 BADBINDINFO.I can not figure out what I'm doing wrong??Thx in advance!

DetailsView edit problem after changing database

Hello!I had a DetailsView control for editing records in a Access 2003 database. I transfered the database to MS SQL 2008 and using the same code does not work - after clicking edit nothing happens (no error) and the record is not updated.ASP code:<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent"> <h2> Urejanje kontaktnih podatkov </h2> <p> <asp:TextBox ID="txtKontaktID" Visible="false" runat="server"></asp:TextBox> <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:conKrik %>" ProviderName="<%$ ConnectionStrings:conKrik.ProviderName %>"  SelectCommand="SELECT tblKontakt.*, tblStranka.strSkrajsanNaziv FROM krik.tblKontakt INNER JOIN krik.tblStranka ON tblKontakt.StrankaID = tblStranka.StrankaID WHERE ([KontaktId] = @id)" UpdateCommand="UPDATE tblKontakt SET strIme = @strIme, strPriimek = @strPriimek, strPoslovnaEnota = @strPoslovnaEnota, strTelefon = @strTelefon, strFaks = @strFaks, strMobitel = @strMobitel, strEmail = @strEmail, rmkOpomba = @rmkO

DetailsView error "must be in edit mode to update a record" when I have set edit mode in code behind

Hi,I have a DetailsView within an UpdatePanel.  I programmatically put the DetailsView into edit mode, change the fields then call the UpdateItem method which causes the "must be in edit mode to update a record" exception.  Am I missing something blindingly obvious? <asp:UpdatePanel ID="upSpecificShout" runat="server" UpdateMode="Conditional" ChildrenAsTriggers="true" > <ContentTemplate> <asp:DetailsView ID="dvSingleShout" DataSourceID="sdsSingleShout" runat="server" AutoGenerateRows="false" OnDataBound="SetDVIcons" HeaderStyle-CssClass="noDisplay" DefaultMode="ReadOnly" AutoGenerateEditButton="true" OnItemCommand="dvItemCommand"> <fields> <asp:TemplateField ShowHeader="false"> <ItemTemplate> <asp:Panel ID="dlSpecificDetailsViewPanel" runat="server" CssClass="i_am_a_shout"> <h2><asp:LinkButton ID="lblShoutTitle" runat="server" Text='<%# Bind("Shout_Title") %>' On

Sharepoint 2010 add/edit form: Insert link from sharepoint disabled




I have a list with enhanced rich textbox field. I can click on Insert link, "from addres" is enabled, but "from Sharepoint" is disabled.

Is there a reason why is this button disabled? Field is enhanced rich textbox... Paste button is also disabled.



Enabling Edit , delete and insert in Data view with linked sources


Hello ....


I create a data view in sharepoint designer 2007 that has linked sources (Join between two lists) ....


How can I enable edit, delete and insert links in this data view  ????.... taking in consideration that options available in data view properties appear in gray ...



Can I use a DetailsView control to insert and update with RIA services?



I'm struggling with trying to use RIA services from an ASP.NET web site.

I created a new web site, added an entity framework model, then added a RIA service that uses that model. I used the DomainDataSource control to bind the ASP.NET controls to the RIA service.

I have a GridView that shows items from the database (via RIA and the entity framework model underneath it), and can see the items fine. I added a DetailsView as a pop-up, as shown in http://mattberseth.com/blog/2007/07/modalpopupextender_example_for.html and http://mattberseth.com/blog/2008/04/masterdetail_with_the_gridview.html. When I click the "edit" link in a row in the GridView, the DetailsView shows with the right data, but clicking the "save" link doesn't actually update the database.

Furthermore, I can't work out how to add new items this way, as when I try and use the DetailsView to add a new item, nothing is sent to the database.

Anyone any ideas how this can be done?


DropDownLists inside Detailsview INSERT cant get to work.



I'm having a DetailsView which has two DropDownList's inside so I should be able to pick 2 values for the field from DDL instead of writing something for it. But I cant get it to Insert any new values to my Database...

Can anyone help me with this? I'm pasting my code and table details here below.

<asp:DetailsView ID="DetailsView1" runat="server" AutoGenerateRows="False"
        CellPadding="4" DataKeyNames="SignUpKey" DataSourceID="LinqDataSource1"
        DefaultMode="Insert" ForeColor="#333333" GridLines="None" Height="50px"
        Width="125px" oniteminserted="DetailsView1_ItemInserted"
        <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />

Insert command not using selected value from DDL in a DetailsView


My web form contains a detailsview control that I have added a templated field to with a DropDownList in the InsertItemTemplate. The DetailsView default mode is 'insert. My detailsview is attached to a sqldatasource that has a stored procedure in the db to handle the insert. When I enter data in the fields and select insert all values from the detailsview are written to the table except for the selection that was made in the dropdownlist. I am using the ddl.selecteditem.value to populate my variable however when the insert method is envoked it doesn't send my value. The DDL value that I am capturing does not need to be written to the table it is just a flag for some variables that need to be set at the stored proc level. How do I get the DDL selected value to be sent with the insert statement? Any help would be greatly appreciated.

Here is my code behind:





Protected Sub

DropDownList1_SelectedIndexChanged(ByVal sender

Detailsview insert


I have a detailsview in insert mode. I want to prompt the user to enter data in all fields, if left empty. Could someone please find a few minutes to show me how to do it?

Thanks in advance.

DetailsView - Cannot insert the value NULL into column


Can somebody tell me why I am getting this error when I try to insert data in a DetailsView 2.0? 

Cannot insert the value NULL into column 'Title', table 'C:\INETPUB\WWWROOT\TEST\APP_DATA\QUIZ.MDF.dbo.Question'; column does not allow nulls. INSERT fails.

I used the Configure Data Source wizard to set this up and Question ID is a autonumber.

When you autogenerate the Insert button on a Detailsview control and click on that button during run time the control posts back with text input areas where you are supposed to type the Title, Answer1, Answer2 etc. Obviously I typed data in to this text area labeled Title. It didn't work and that's why I'm asking about the control. Because I can't debug the control I am having a hard time figuring out where the problem is.

Here is the code and thanks for any help.

<asp:DetailsView ID="EditDetails" runat="server" Height="50px" Width="550px" AutoGenerateRows="False"  AutoGenerateInsertButton="True" AutoGenerateEditButton="True" AutoGenerateDeleteButton="True" CellPadding="4" DataSourceID="SqlDataSource1" ForeColor="#333333" GridLines="None" AllowPaging="True">
                        <FooterStyle BackColor="#5D7B9D" Font-Bol

DetailsView Get Values on Insert. Major Problem :(



I'm having a problem to get the inserted values from the detailsview. I've tried the following things:

           // Get Value from DropDown
        int TopicID = 0;
        foreach (DetailsViewRow row in ItemsDetailsView.Rows)
            if (row.Cells[0].Text == "Topic")
                 DropDownList TopicDropDown = (DropDownList)row.Cells[1].FindControl("Topic_TopicIDList");
                 TopicID = int.Parse(TopicDropDown.SelectedValue.ToString());


            MsgBox(CType(DetailsView1.Rows(1).Cells(0).Controls(0), Label))

            For Each row As DetailsViewRow In DetailsView1.Rows

                Dim cell1 As TableCell = row.Cells(1)

                Dim value1 As String

                value1 = cell1.Text



            Dim item As New DetailsViewItem(col.ColumnName, row(index).ToString(), col.DataType.ToString(), col.DefaultValue)


            tb = DetailsView1.FindControl("Categorie")
            s = tb.Text


            For Each dvr As DetailsViewRow In DetailsView1.Rows
                If dvr.Cells.Count = 2 Th
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend