DetailsView: conditionally hide field if value == null, but can't update the value of other fields

Hi,

I need help please.

I have made some fields hidden if their value is null by setting visible to false on the DetailsView1_Itemcreated event. I put the field's to the DataKeyNames, so that I can check the value is null or not when detailsview is at the readOnly mode.

But, when I tried to edit, it throws an error: must declare a scalar for @...  so, i add some code in the DetailsView1_ItemUpdating: e.newValues["color"] = null; then the error is gone. but, the values for other fields are not updated.

I already check the e.newValues["other fields"] , they all are updated. but, procedure doesn't seems to call them?  I'm using SQLDataSource.

It's weird because when all fields appears (no hidden fields) , the update procedure works. And also, for insertion in both cases (there is hidden fields, or no hidden fields), the insertion procedure works, too.  

 

I'm really confused now, I've searched on the internet for solution, but they are not really what I'm looking for.  

0
EvoPrototype
9/12/2008 2:01:26 AM
asp.net.presentation-controls 72751 articles. 3 followers. Follow

4 Replies
1090 Views

Similar Articles

[PageSpeed] 24

How about modifying your select to not include nulls.  Do you have to display those columns or rows if the key values are null.


Solutions Architect
Coden Enterprises
http://www.codenenterprises.com/iblog
0
codenenterp
9/12/2008 2:57:00 AM

Yes, I have to show the other fields, even if one field is null. 

(Example)

Data 1: 

Name: evo

Last Name: prototype 

(hobby == null, so visible= false)

Class taking now: CS
 

Data 2:

Name: evo2

Last Name: prototype2

Hobby: basketball 

 Class taking now: art

 

now, I can't update the value for "class taking now" for data 1, but for data 2 it works. and for insertion it works too for both. just because I made it hidden, the update procedure is corrupted? 

0
EvoPrototype
9/12/2008 2:22:37 PM

 is it because I use ConflictDetection="CompareAllValues" on the SQLDataSource ?

How can I update the row if one of the fields' value is null?  how do you fixed "must declare a scalar for @..." error correctly?

 

Please help.
 

0
EvoPrototype
9/12/2008 5:14:57 PM

I have figured it out. how to update it, even though I think it's kind of risky.

so basically, from this thread: http://forums.asp.net/p/1307688/2616360.aspx#2616360

I modified the UPDATE procedure:

FROM: 

UpdateCommand="UPDATE [Table] SET [ID] = @ID, [name] = @name, [lastname] = @lastname, [hobby] = @hobby WHERE [ID] = @original_ID AND [name] = @original_name AND [lastname] = @original_lastname AND [hobby] = @original_hobby"

TO:

UpdateCommand="UPDATE [Table] SET [ID] = @ID, [name] = @name, [lastname] = @lastname, [hobby] = @hobby WHERE [ID] = @original_ID AND [name] = @original_name AND [lastname] = @original_lastname"

 

I'm guessing because when [hobby] = @original_hobby -->  [hobby] = null -> this cause the problem. I don't know else how to fix this, and I know it's kind of risky for conflict, but I guess ID is the determination to not be conflict.

If anyone know better solution, please let me know, Thank you.

 

-Evo 

0
EvoPrototype
9/12/2008 5:49:16 PM
Reply:

Similar Artilces:

How to Store NULL Values in Decimal and numeric field when the user doesn't enter any value
Hi, Actually i m working in 3-tire Architecture I have a table which contains both numeric and Decimal field. When the user does not give input to the textbox which is of decimal/numeric type and clicks submit button Error Comes as Below: Input string was not in a correct format. So plse help me out since i m using a 3-tire Arch. Reply as Earliest Thanks in Advance   Parrameswaran.P.R use System.Data.SqlTypes.SqlDecimal.Null to insert NULL into ur DatabaseMAKMark as Answer if this reply helps youMVP ASP/ASP.NetASP.Net Hosting : Host DepotMy Site : ASPSni...

Checkbox data-bound to a bit SQL field can't handle NULL values
I have a checkbox on my webform that is bound to a bit field in my SQL table. I'm fine as long as I've got the bit field set to 0 or 1, but if the field is NULL, the checkbox throws an exception during the databind. Is there any way to handle this without removing the data binding and manually setting the value (ie: some way to intercept it before the exception gets thrown and then setting the field value in the dataset)? Thanks! Hi, You may try to use the ISNULL() function in your SELECT statement, or you can use a Helper Function to do so. Colt...

Hyperlink treated as null value, detailsview when hiding null fields
I've tried everything I know (limited, I'll admit).  I have a DetailsView displaying off a Gridview when a user makes a selection in Gridview.  I also have many fields where some will be populated and some not.  Rather than showing all the empty fields on the detailsview I have code behind to loop through the detailsview and only show cells with data in them.  Problem is, one of the cells is a hyperlink with a variable and it is getting dropped from view when I loop in the code behind.  If I comment out my code behind for hiding null values, all works fine on...

Can't update my database because I can't retrieve the value from radiobuttonlist
Hello I am a beginner in ASP.NET and I am now developing a poll application but I had a problem and I could not solve it. The problem is that I could not use an update query because my SQL statement cannot retrieve the value from radiobuttonlist . I am now stack in this point and I could not complete my application. I could not  attach the website because I am not allowed. I don't know why. Note : the error message is  No value given for one or more required parameters.   My CODE : Conn.Open() Cmd3 = New OleDbCommand("Update PollAnswer Set PollCount = PollCount + 1 Where...

How can I add 2 fields value to 1 fields value in a GridView?
Hi all!I have one access database named=Medlemmar.mdb and Tablename=TidBokning and with some columns ex. "Bokad_For" and "Plats".Let say that "Bokad_For" contains value "Group2" and "Plats" contains value "Stockholm".Now I want to make this 2 value to 1 fileds like this: "Bokad_For" contains value "Group2Stockholm"How can I do that?I use asp.net 2.0 and C#.I tried with Eval("Bokad_For") and somthing, but Eval works only in Templates (I guess) I cant get Templates to work in my GridView.i'm newbee in this and think I need some help here :-) ?Thanks for all help!Micael Roxenhall You can sol...

How to INSERT INTO [Table] ([Field]) VALUES('I Have a ' in value')
Hi, I want to INSERT INTO [Table] ([Field]) VALUES('I Have a ' in value') please teach me how to xxx INSERT INTO [Table] ([Field]) VALUES('I Have a '' in value') instead of one single quote, u need to add one more.Om Prakash Use Parameterized Queries ...you woudnt have to worry about escape characters besides saving your db from sqlinjection attacks. hth***********************Dinakar NethiLife is short. Enjoy it.***********************...

Unable to update the values for the cloumn which have null values in detailsview control
i m updating a record in a details view by clicking update button. I m able to change the values of the various columns which have non null values. However update is not working when the value of the cloumn is a null value in the database. Any idea how to resolve this?RAJAT Do you get an error or does the update simply not work?Are you capturing the error using the "ItemUpdated" event by checking e.Exception?  http://authors.aspalliance.com/aspxtreme/sys/web/ui/webcontrols/DetailsViewClassItemUpdated.aspxhttp://www.rocksthoughts.comhttp://www.jumpstarttv.com - Free Techn...

can i hide a field if the value in the DB is null
Hi guys Newbie using vb.net sql express and VISUAL STUDIO 2005.Im sure this is a simple answer but any help and information would be greatly appreciated.  If i pull some data from my db using an sql datasource and display using labels and text boxes, am i able to hide labels and text boxes that would contain a NULL VALUE, as in the backend Database the values are null. Id want to do this on page load.Any tutorials, code examples and help would be greatly appreciatedKind Regards TeddyNo one said it was gonna be easy, then again, nothing worth doing ever is. Yes, you can use the IsDbN...

DetailsView ItemInserting Values collection empty and can't retrieve values
I'm sure this is something really silly but I can't seem to figure it out. I have a DetailsView for entering data and I wired up the ItemInserting event to manually insert a new record in a DataSet that is being persisted in Session. When I set a breakpoint in the ItemInserting routine the values collection is empty and even trying to retrieve the text from the textboxes in the DetailsView returns empty strings.  Here's a sample of exhibits the problem.  <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs"...

Can't get the value from a password field !
Hi, I have a small trouble with a password field. I designed initially the front end with other IDE which used normal HTML code in defining the GUI. As you'll see these two fields are inside a "div" and also placed into a <FORM> tag. I also saw that if I didn't include the "method=post" into these <FORM> tags the name and its value of these two text fields are added to URL in the browser. This problem is solved now. But...if I want to get the values out of this fields in the server side of the code I can get the vale just for one of these text fiel...

Value property using FCKEditor in ATLAS is not updated, can't get Value
Hi,  I am using the ASP.NET integration of FCKEditor v2.2 inside an Atlas UpdatePanel.In a postback the editor's value is not updated and I can't get the value property of the control.  Is there any work around known?  Regards, HSHUeslei...

Why couldn't a string variable store value, but a button control can store value?
After I run the following code, I first click the button "button1", then I click the button "button2"The result displayed in the textbox control is "Btn1", but I hope get the result "I have clicked Btn1"! Why couldn't a string variable store value, but a button control can store value? Do I must add the keyword "static" before the code "string aa = """? Are there difference between adding the keyword "static" or not? Are there other better ways to store temporary工value?   <%@ Page Language="C#" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3...

Does the agregated funcion List(field) returns a SORTED list of not NULL field's values?
Hello... I have this SELECT statement: SELECT List(part) FROM invoice_detail WHERE delivered='N' GROUP BY invoice_no HAVING Count(invoice_no)>1 ORDER BY invoice_no Which returns me the following rows: BR122-L,BR122-S BR145-L,BR145-T STH1451,STH1452 STH1457,STH1458 STB3451,STB3452 ARK1345,ARK1346 KYR4670,KYR4671 What I would like is to be certain on having the items on the list always sorted. What can I do for it? Thanks. Version 9 introduced the ORDER BY clause to the LIST function: LIST "(" <expressio...

Field that controls the values that appear in this field
--_009_EEA7F24FEA5EDC42BC3FD72846A5D8F84138437CAMSPRD0711MB593_ Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Hi, Can I use the option of "Field that controls the values that appear in this= field" for non-custom fields? Thanks, Shalom. Shalom Shevach | QA Manager Comigo Ltd. O: +972- 9-771-5090 Ext. 119 | F: +972- 9-771-5091 | www.comigo.com<http= ://www.comigo.com/> E-mail: shalom.shevach@comigo.com<mailto:shalom.shevach@comigo.com> [Description: Description: Comigo]<http://comigo.com/&...

Web resources about - DetailsView: conditionally hide field if value == null, but can't update the value of other fields - asp.net.presentation-controls

MOC conditionally approves Nokia-Microsoft deal
According to the announcement by the Ministry of Commerce, the Ministry is in the point of view that...

Christie Conditionally Backs New Jersey Internet Gambling
New Jersey Governor Chris Christie Thursday gave his conditional support to Internet gambling, laying the ground for the state to become one ...

N.Y.U. returns, conditionally, to salvage LICH deal
SUNY and Fortis bring hospital back, but only if judge dismisses nurses' union suit

Maltese PM says Greece would conditionally suspend bailout referendum
Greece has said it would be willing to suspend Sunday's planned referendum on the latest cash for reforms offer from its creditors if talks were ...

China approves conditionally Western Digital's acquisition of Hitachi
China has approved with conditions Western Digital's planned acquisition of Hitachi Global Storage Technologies (GST), requiring that the Hitachi ...

Chris Christie approves medical marijuana for children – conditionally
Christian Science Monitor Chris Christie approves medical marijuana for children – conditionally (+video) Christian Science Monitor Enlarge. ...

Chris Christie 'conditionally vetoes' minimum wage increase, Democrats saying screw your conditions
New Jersey Gov. Chris Christie conditionally vetoed a bill raising the state's minimum wage from the federal rate of $7.25 to $8.50 and tying ...

Chris Kluwe Conditionally Surrenders No. 5 To New Vikings QB Donovan McNabb
Your morning roundup for July 30, the day we're provided with living proof that 32-year-old women are, in fact, into 83-year-old men. Got any ...

MOEA conditionally approves Sanan Optoelectronics stake in Epistar
Taiwan's Ministry of Economic Affairs (MOEA) on October 29 approved the conversion of China-based LED epitaxial wafer and chip maker Sanan Optoelectronics' ...

Judge conditionally bars Samsung from pointing next week's jury to the Apple-HTC settlement deal
... construction) to a greater extent than on commercial considerations (such as the eBay injunction factors). However, I find her order conditionally ...

Resources last updated: 11/30/2015 12:30:21 PM