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

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

DropDownLists inside Detailsview INSERT cant get to work.

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


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" />

View Complete Post

More Related Resource Links

RadioButton inside GridView, How to get it work as normal

Did you tried before to drag a RadioButton control inside a Gridivew templatefield, and then you attempt to select these RadioButtons , you will notice that the behavior of RadioButton control will be changed and it will work just like the behavior of checkbox control! the user will be able to select more than one radiobutton in the grid!

INSERT Statement Inside a UDF?

I am using SQL Server 2005.  I know you can not put INSERT or UPDATE statements in a UDF.  I am looking for an alternative to getting the end result I need since this call has to go at a specific point in the code or it will never work.  I have a UDF which packs smaller boxes into a bigger box efficiently.  The UDF typically runs and creates as many bigger boxes as possible until all smaller boxes are used and then it returns a TABLE variable back to a stored procedure.  I need to insert a record into a new table at the point where each bigger box is full before it moves on to the next bigger box.  There is only a couple alternatives I can see but don't really know if each is possible.  I am open to an ideas: 1. Call a stored procedure from the UDF which executes the insert statement 2. Using EXECUTE to perform the insert statement 3. Re-write the UDF as a stored procedure.  It must be able to table two inputs and return a table which can be unioned with two other views. 4. Anything Else UPDATE: Scratch idea #1 since it says I can only call other functions or extended stored procedures UPDATE: Scratch idea #2 as it did not work

Get value of a label control inside the DetailsView

Hi everyone, I have a databound label control (i.e. Label 3) inside an Item Template that's in a DetailsView control. I just need to get the value of those label and compare it to some string. I tried several ways (i.e. Find control, DetailsView.Row) but nothing seems to work. I don't know if I'm using the FindControl methos correctly or if I need to access the Row first and do the findcontrol method.  Protected Sub DetailsView4_DataBound(ByVal sender As Object, ByVal e As System.EventArgs) Handles DetailsView4.DataBound 'If (DetailsView4.Rows(2).Cells(1).ToString = "Regular") Then 'Label3.ForeColor = Drawing.Color.Azure 'End If 'Dim StatusQualifierContainer As Label 'Dim S As String 'StatusQualifierContainer = DetailsView4.FindControl(Label3.Text) 'S = StatusQualifierContainer.Text 'If S = "Regular" Then 'Label5.ForeColor = Drawing.Color.Aqua 'End If 'Dim C As Label = DetailsView4.FindControl("Label3") 'If C.Text = "Regular" Then 'Label3.ForeColor = Drawing.Color.DarkBlue 'End If 'Dim headerRow As DetailsViewRow = DetailsView4.HeaderRow 'Dim lblText As Label = CType(headerRow.FindControl("Label3"), Label)

Insert Into SQL Server inside a For Each - Next Statement

I have the following code to For each Item in the file uploader, Insert Into database.... but It doesnt work in the For Each Statement but if i take it out of the For Each statement it works.   For Each item As AttachmentItem In Attachments1.Items            Dim objConn2 As New SqlConnection("Data Source=XXX")            objConn2.Open()            Dim objCmd2 As New SqlCommand("INSERT INTO clientport (name, event, date1, username, password, path)" & "VALUES (@name, @event, @date1, @username, @password, @path)", objConn2)                                 objCmd2.Parameters.AddWithValue("@name", clientname.Text)            objCmd2.Parameters.AddWithValue("@event", [event].Text)            objCmd2.Parameters.AddWithValue("@date1", [date].Text)            objCmd2.Parameters.AddWithValue("@username", username.Text)  &nbs

Does the ReportViewer control print button work inside of a modal MSIE window?

I am getting the following two error messages when using the new ReportViewer v10 control after pressing the toolbar print button. I am only seeing this error inside of a modal popup window in MSIE. The print button in a normal popup window doesn't have this error. An error occurred trying to get the current window Error: Could not complete the operation due to error 8007f305. If anyone knows of a quick fix, please let me know. Thank you. VS2010, MSIE 8, SQL Server 2008.

Cascading DropDownLists in DetailsView

Hi guys,My first post ;]I am a beginner in asp.net and therefore, cause problems that for me seem unsolvable.I hope someone can help me resolve this. Thank you.Here is the case:I use Visual Studio 2008 ASP.NET 3.5I have a DetailsView control with several fields that is in insert mode. Three of them are the source of my problems and headaches.I have three DropDownLists in template fields.The first one is OK, bound to it's designated field in table1 in the database. The next two however have to change their bound tables according to the SelectedValue. So far, I've managed to get it working, BUT when I insert the data I've entered, these two DropDownLists are not entered into the database.DropDownList3 - the list that controls the other two DDLsDropDownList4 and DropDownList5 - the list that need to change their items accordinglyDropDownList3 has six different values, so I have 6 tables for each of the other two DDLs However I have only tried with one to see if it would work, that's why the Sub seems incomplete.Here is the relevant part of the code: <asp:TemplateField HeaderText="Category" SortExpression="category"> <EditItemTemplate> <asp:TextBox ID="TextBox3" runat="server" Text='<%# Bind("category") %>'></asp:T

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!

DropDownList inside FormView Insert Template

Hi, I am trying to change the textboxes in the FormView insert template to dropdownlists but they keep setting the parameters to null.   Here's what I have:  <asp:DropDownList ID="ddlYearOfQualification" SelectedValue='<%# Bind("YearOfQualification") %>' runat="server"> </asp:DropDownList> In Page_Load CType(frmSurvey.FindControl("ddlYearOfQualification"), DropDownList).Items.Add(New ListItem("2010", "2010"))CType(frmSurvey.FindControl("ddlYearOfQualification"), DropDownList).Items.Add(New ListItem("2009", "2009"))   and in the SqlDataSource InsertCommand="INSERT INTO [tblSurvey] (... [YearOfQualification] ...) VALUES ( ... @YearOfQualification ... ) And in insert parameters: <asp:Parameter Name="YearOfQualification" Type="Int16" /> And the insert fails with YearOfQualification as null. If I sue the standard textbox: <asp:TextBox ID="YearOfQualificationTextBox" runat="server"                 Text='<%# Bind("YearOfQualification") %>' /> It works.   Any ideas? Many thanks in advance.

RequiredFieldValidtor does not work when embed inside server control

Hi, Do any one have any idea how to implement requiredfieldvalidtor. Server control which i have created does not work on client side. No javascript is been rendered and onSubmit the page.isvalid  returns true.  protected override void OnPreRender(EventArgs e) { PlaceHolder TextBoxPlaceHolder1 = null; PlaceHolder TextBoxPlaceHolder2 = null; PlaceHolder TextBoxPlaceHolder3 = null; WebControl InputControl = null; RequiredFieldValidator RequireValidator = null; Image Img = null; if ((this.FindControl(_TextBoxControl) == null) && (_TextboxPlaceHolder == null)) { Img = new Image(); _TextboxPlaceHolder = new PlaceHolder(); _TextboxPlaceHolder.ID = _TextBoxControl; if (_HasChildControl == false) { TextBoxPlaceHolder1 = new PlaceHolder(); TextBoxPlaceHolder1.ID = "LeftPanel"; TextBoxPlaceHolder2 = new PlaceHolder(); TextBoxPlaceHolder2.ID = "CenterPanel"; TextBoxPlaceHolder3 = new PlaceHolder(); TextBoxPlaceHolder3.ID = "RightPanel"; TextBoxPlaceHolder1.Controls.Add(_Label.GetControl());

BULK INSERT with a UNC path does not work even with delegation

I have a stored procedure that uses BULK INSERT with a UNC path to another server. I have enabled both the server and the domain account the SQL Server services are running under to allow all delegation. The UNC path allows Everyone Full Control. I can log into my computer using the SQL Server service account and browse to the file and open it. I can log onto the SQL Server with the service account or my account and browse to the file and open it. Whenever I run the stored procedure or execute the BULK INSERT from SSMS I get the following: Msg 4861, Level 16, State 1, Line 2 Cannot bulk load because the file "\\nas\shared\ZipSales\FLAT.txt" could not be opened. Operating system error code 5(Access is denied.). I can log into the server console using my user account, open SSMS on the server, and the stored procedure or the raw BULK INSERT work just fine. It's only a problem when I execute it from an end user workstation. Moving the data file to the SQL server works fine, but that is not a viable long-term solution. After scouring the Internet for most of two days, I finally stumbled across <a href="http://social.msdn.microsoft.com/Forums/en-US/sqlsetupandupgrade/thread/512fe230-b94a-4fe0-83c8-201a150bbcec">another post</a> that has this bit:  "After watching forums, etc. for almost a year regarding this issue, we ran a MS Support Reque

User Control with JQuery doesnot work inside update panel


Hi All,

I created a .NET user control to work as a DropdownCheckbox and added Jquery to give the sliding and hide effects. The code is as below:

 <script language="javascript" type="text/javascript">
        var showRegionWindow = function (ev) {
            var pos = $("#lnkChangeRegion").offset();
            var width = 230;
            var height = 55;
            //$("#changeRegionPanel").css({ "left": +((pos.left) - 215) + "px", "top": height + 16 + "px" });.
            document.getElementById("lnkChangeRegion").style.display = 'none';

        var hideRegionWindow = function (ev) {
            var textVal = "";

Validator inside DetailsView always renders on a new line


I have the following markup:

<asp:TemplateField HeaderText="Name" SortExpression="Name">
<asp:TextBox ID="txtName" runat="server" />
<asp:RequiredFieldValidator ID="valName" runat="server"
ErrorMessage="Name required." ControlToValidate="txtName"

The Validator text appears on a new line immediately after the TextBox.  I would like it to appear immediately after the TextBox (i.e. to the right of it).

I've tried two things to fix this:

1. I put the markup on the same line, e.g.:

<asp:TextBox ID="txtName" runat="server" /><asp:RequiredFieldValidator ... />

2. I tried putting the TextBox and Validator in the same html table cell.

Both strategies failed.  Any other ideas out there?  I appreciate your help!

Problem with Editing image inside DetailsView inside UpdatePanel



I have a problem and I really hope you'll be able to help me.

I'm trying to add and edit an image which is located in a detailsview which is inside an UpdatePanel. After I read relevant topics in the forum I installed the Ajax Control Toolkit. Below is my source code. When I used it only for insert new image it worked great. The problem caused when I tried to implement it on the Edit mode, i.e. when I tried to edit the image and upload a different image.  Unfortunately it didn't work as I hoped. Nothing happend and the image hasn't been changed. I also tried to change the IDs (AsyncFileUpload ID) to be the same in both places but it didn't work either.

The source code:

<asp:DetailsView ID="dvMovie" runat="server" Height="50px" Width="695px"
                    AutoGenerateRows="False" DataSourceID="sdsMovieById"      
                     BorderColor="#E7E7FF" BorderStyle="None" BorderWidth="1px"

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?


bulk insert work not correct


i have data-file with 12 fields and ";" is field terminator.

but in data-file in some rows last fileds can absent.

when i use "bulk insert" to insert to my table in DB by used format file where all fields described, some rows (one with absent fields and next one)  are inserted in the same row (into last fields).

for example





in table

1_1;2_1;3_1;;;;6_1;;;9_1(there are row terminator symbols) 1_2;2_2;3_2;(4_2;5_2;6_2;7_2;8_2;9_2;10_2;11_2;12_2) - these are in one field

1_3;2_3;3_3;4_3;5_3;6_3;7_3;8_3;9_3;10_3;11_3;12_3 - next row in table is normal

how i can decide this?

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

FindControl In DetailsView Edit & Insert ItemTemplate


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
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