This is a discussion on ASP.NET Data Controls within the ASP and ASP.NET Programming forums, part of the Web Development category; hi guys, I am using Visual Studio 2005 and ASP.NET 2.0 and SQL Server Express 2005 Ok I'...
| |||||||
| Register | FAQ | Members List | Calendar | Mark Forums Read |
| |||
| hi guys, I am using Visual Studio 2005 and ASP.NET 2.0 and SQL Server Express 2005 Ok I've come up with the next problem: I want to check if a field has a value and if it has it should display it, otherwise it shoudn't. Now In my database I've got fields wich have the Nulls allowed properties.These fields will have the initial value of NULL and when I erase the NULL value it will have no value. So Im using the next statements to check this: <%#IIf(IsDBNull(DataBinder.Eval(Container.DataItem , "Adreslijn2")) , "" , DataBinder.Eval(Container.DataItem, "Adreslijn2") & "<BR />")%> This will work if the field has the initial NULL value but if it has no value or a value, both ways it will give no error but it will still print the breakline even if it has an empty value because it is not NULL ofcourse while it also shouldn't print the breakline if it has an empty value. <%#IIf(DataBinder.Eval(Container.DataItem, "Adreslijn2") = ""), "" , DataBinder.Eval(Container.DataItem, "Adreslijn2") & "<BR />")%> This will work if the field has no value (so when I have erased the initial NULL value) but when the field still has the initial NULL value it will give the following error: Operator '=' is not defined for type 'DBNull' and string "". Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.InvalidCastException: Operator '=' is not defined for type 'DBNull' and string "". Using OR in the IIF line of course also does not work because it will still give the error when the field contains the NULL value Does anyone here know a solution for this? Is it maybe possible to give my fields in my database an initial empty value instead of NULL so when a new record is created it will fill the empty records with no value instead of NULL or is there another solution to this? Thanks in advance
__________________ Venkat knowledge is Power |
| Sponsored Links |
| |||
| Hi venkat, Try using <%#IIf(String.IsNullOrEmpty(DataBinder.Eval(Contai ner.DataItem, "Adreslijn2")) , "" , DataBinder.Eval(Container.DataItem, "Adreslijn2") & "<BR />")%>
__________________ H2O Without us, no one can survive.. |
| |||
| hi H2o, Thanks for trying to help but I've tried it and it doesn't work when the value of the field is NULL I get this error: Conversion from type 'DBNull' to type 'String' is not valid. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.InvalidCastException: Conversion from type 'DBNull' to type 'String' is not valid. I think I should have to construct something like IF (thedataitem is DBNull) THEN do action ELSE IF (the dataitem is empty) THEN do action ELSE do other action... but I have no idea how to do that inside a repeater using IIF...
__________________ Venkat knowledge is Power |
| |||
| hi, OK... try this... <%#IIf(IsDBNull(DataBinder.Eval(Container.DataItem , "Adreslijn2")) OrElse String.IsNullOrEmpty(DataBinder.Eval(Container.Dat aItem, "Adreslijn2")) , "" , DataBinder.Eval(Container.DataItem, "Adreslijn2") & "<BR />")%>
__________________ H2O Without us, no one can survive.. |
| |||
| hi, No worries!! I think you might be getting confused here!! There aren't any "IIF functions" as you describe them. IIF is a function which compacts a normal IF condition THEN condition_is_true_value ELSE condition_is_false_value END IF into 1 line... so really it's about understanding how the 3 component parts work... and getting your logic right!! So in your case with IIf(condition, true_value, false_value) you're comfortable with the true_value and false_value, but not building the condition itself. Well the condition can be any VB you want... in this case you could've written your own function that checks to see if the value is DBNull or String.Empty and then returns a Boolean... and then called that. Instead I put the logic inline for you with judicious use of OrElse... this is something that is very important to understand... statement1 And statement2 - this means that both statement1 and statement2 will be evaluated and both must be true statement1 Or statement2 - this means that both statement1 and statement2 will be evaluated and either one must be true statement1 AndAlso statement2 - this means that both statement1 and statement2 must be true, but if statement1 is false statement2 is not evaluated statement1 And statement2 - this means that either statement1 or statement2 must be true, but if statement1 is true statement2 is not evaluated Hope this all makes sense!
__________________ H2O Without us, no one can survive.. |
| |||
| Are you defining the name of your checkbox explicitly? It is not enough to The Repeater control renders a read-only list from a set of records returned from a data source. Like the FormView control, the Repeater control does not |
| |||
| what are the differences between property and local variable in C#??? The Local variable defined inside the class adds up to the state definition of the object during runtime, So when I say any object is in valid state I necessarily mean that every member/local field of the class has it's value in the desired and appropriate state. A property is the interface provided for the outside world to access any particular field of the class to manipulate the object state in the controlled way. That's why it's the standard practice to encapsulate the public fields through the properties. The properties can control the access to internal fields through the get and set functions, you can choose to implement any one or both the functions in order to control the access based on the requirement. Apart from the controlled access and security the properties also offer another major advantage over the public field like, say if any exception is raised when setting any particular field the field may be left in the invalid state, where as if any exception occurs while accessing the field through the property the old value is retained automatically there by laving the encapsulated field in the valid state even though the exception occurs.
__________________ A.Rajesh Khanna |
| |||
| Hi, I am facing a painful problem using DatePicker in DataGrid. The problem is the when I am clicking the date in the popped up calender, the date is getting greyed but the date value is not getting into the datagrid textbox. The code is given below: <EditItemTemplate> <Asp:TextBox ID="txtHelpDeskRequestDate" Text='<%# DataBinder.Eval(Container.DataItem, "HelpDeskCallDate" ) %>' runat="server" Width="70px" ReadOnly="false"> </Asp:TextBox> <a href="javascript:;" onclick="calendarPicker('form1.txtHelpDeskRequestD ate');" title="Pick Date from Calendar"><img src="/cal.gif" width="16" height="16" border="0" alt="Click Here to Pick up the timestamp" align = "left"> </a> </EditItemTemplate> The function is like this: function calendarPicker(strField) { window.open('/DatePicker.aspx?field=' + strField,'calendarPopup','width=250,height=190,res izable=yes'); } Please Help |
| |||
| One of the most powerful server controls in ASP.NET is no doubt the DataGrid control. The DataGrid control is a multi-column, data-bound ASP. __________________________________________________ ____ top hosting company cheap web hosting |
![]() |
| Thread Tools | |
| Display Modes | |
| |
LinkBacks (?)
LinkBack to this Thread: http://www.discussweb.com/asp-asp-net-programming/3113-asp-net-data-controls.html | |||
| Posted By | For | Type | Date |
| ASP.NET Data Controls - Page 2 - DiscussWeb IT Community - Technical Support and Technology Discussions | This thread | Refback | 08-27-2007 12:10 AM |
| DiscussWeb IT Community - Technical Support and Technology Discussions | This thread | Refback | 08-17-2007 02:02 AM |
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| How can we Dynamically create web controls | Kirubhananth | ASP and ASP.NET Programming | 3 | 03-14-2008 09:00 PM |
| WebParts controls | S.Vinothkumar | ASP and ASP.NET Programming | 5 | 11-16-2007 02:06 AM |
| How to add controls into the page dynamicaly | kingmaker | ASP and ASP.NET Programming | 1 | 07-23-2007 06:39 AM |
| Asp.net controls not supported by Ajax? | Gopisoft | ASP and ASP.NET Programming | 0 | 07-16-2007 11:22 PM |
| MFC Updates for Vista Common Controls | Karpagarajan | C and C++ Programming | 0 | 03-29-2007 01:32 PM |