473,394 Members | 1,739 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

check Empty DataList

I am using ASP.NET and VB to display a message(label) while the datalist is empty like this

Expand|Select|Wrap|Line Numbers
  1. <asp:Label ID="lblEmpty" Text="No Data To Display"  runat="server" Visible='<%#bool.Parse((dlErgebnis.Items.Count==0).ToString()) %>'></asp:Label>
I am getting a error "the name bool is not declared".

What is causing this error?
Feb 26 '10 #1
14 6992
ThatThatGuy
449 Expert 256MB
Visible='<%#bool.Parse((dlErgebnis.Items.Count==0) .ToString()) %>
this is where you're commiting the biggest mistake....

You can do the same via ternary operator like this
Expand|Select|Wrap|Line Numbers
  1. Visible='<%(dlErgebnis.Items.Count==0)?true:false;%>'>
  2.  

Correct me if i was wrong
Feb 26 '10 #2
Hallo Thatthatguy ,

I have tried as you said iam getting the error as below

Error 1 object of type System.String can not dlErgebnis.Items.Count from its string representation '% (== 0)? True: false;%> for the Visible property to be created.

Thank you .

sarab
Feb 26 '10 #3
semomaniz
210 Expert 100+
Try this

Expand|Select|Wrap|Line Numbers
  1. Visible='<%(dlErgebnis.Items.Count=0)?true:false;%>'>
  2.  
Remove one of the equals to sign, Count is and integer not string.
Feb 26 '10 #4
Hallo Semomaniz,

Thank you for your reply.. i tried that also but not successful..
Feb 26 '10 #5
semomaniz
210 Expert 100+
Why dont you do this in a code behind?

Put this code in page load event or right after you bind the control

Expand|Select|Wrap|Line Numbers
  1.  
  2. If dlErgebnis.Items.Count= 0 then
  3.    lblempty = "No data was found ";
  4.  
  5.  
Also refer to this posting http://bytes.com/topic/asp-net/answe...empty-datalist
Feb 26 '10 #6
Hallo semo,

Thanks for your reply. I have a problem again. if i put this code

Expand|Select|Wrap|Line Numbers
  1.  dlErgebnis.DataBind()
  2.         If dlErgebnis.Items.Count <= 0 Then
  3.             lbdata.Visible = True
  4.             lbdata.Text = "Keine datei"
  5.         Else
  6.             lbdata.Visible = False
  7.         End If
in datalist_load it works but when i put the code in the button_click it doesn't show the message in the label .. What is the mistake i am doing ?..

any idea..
Mar 1 '10 #7
semomaniz
210 Expert 100+
Which button click event are you referring to? If the button binds the data to the data grid you dont have to put the code all you have to do is create a function that pulls the data from the database and binds the data to the datalist, put the datalist check inside the function after binding the data and then you can call the function from any where in the code and still achieve what you are looking for.
Mar 1 '10 #8
Hallo Semo,

This my aspx code.
Expand|Select|Wrap|Line Numbers
  1. <div id="Eingabe" runat="server">
  2.         <p>Firma oder Person: </p>
  3.         <asp:TextBox ID="tbSuchstring" width="400px" runat="server" />
  4.         <asp:Button ID="btnSuchen" runat="server" Text="Suchen" />
  5.         <asp:CustomValidator ID="CVtbSuchstring" runat="server" OnServerValidate="CVtbSuchstring_ServerValidate" />
  6.  
  7.     </div>
  8.  
  9.     <div id="Ergebnis" runat="server">
  10.         <asp:DataList ID="dlErgebnis"  runat="server" DataSourceID="ObjectDataSource1">
  11.             <ItemTemplate>
  12.                 Liste: <asp:Label ID="SLL_SPL_LIST_TYPELabel" runat="server" Text='<%# Eval("SLL_SPL_LIST_TYPE") %>' />
  13.                 <b><asp:Label ID="SLL_SPL_LAW1" runat="server" Text='<%# Eval("SLL_SPL_LAW1") %>' /></b>
  14.                 - Eintrag vom <asp:Label ID="SLL_SPL_ENTRY_DATE" runat="server" Text='<%# Eval("SLL_SPL_ENTRY_DATE", "{0:d}") %>' /><br />
  15.                 <asp:Label ID="SLL_SPL_NAME1Label" runat="server" Text='<%# Eval("SLL_SPL_NAME1") %>' />
  16.                 <asp:Label ID="SLL_SPL_NAME2Label" runat="server" Text='<%# Eval("SLL_SPL_NAME2") %>' /><br />
  17.                 <asp:Label ID="SLL_SPL_STREETLabel" runat="server" Text='<%# Eval("SLL_SPL_STREET") %>' />
  18.                 <asp:Label ID="SLL_SPL_HOUSE_NUMBERLabel" runat="server" Text='<%# Eval("SLL_SPL_HOUSE_NUMBER") %>' /><br />
  19.                 <asp:Label ID="SLL_SPL_CITYLabel" runat="server" Text='<%# Eval("SLL_SPL_CITY") %>' />
  20.                 <asp:Label ID="SLL_SPL_DISTRICTLabel" runat="server" Text='<%# Eval("SLL_SPL_DISTRICT") %>' /><br />
  21.                 <br />
  22.                 <br />
  23.                 </ItemTemplate>
  24.                <FooterTemplate>
  25.                </FooterTemplate>
  26.            </asp:DataList>
  27.         <asp:ObjectDataSource ID="ObjectDataSource1" runat="server" OldValuesParameterFormatString="original_{0}"
  28.             SelectMethod="GetData" TypeName="DataSetComplianceTableAdapters.DataTable1TableAdapter">
  29.             <SelectParameters>
  30.                 <asp:ControlParameter ControlID="tbSuchstring" Name="SLL_SPL_NAME1" PropertyName="Text"
  31.                     Type="String" />
  32.             </SelectParameters>
  33.         </asp:ObjectDataSource>
  34.  
  35.     </div>
I think just the btn click will fetch the data. i only need to check the datalist is empty or not in the button click.
Mar 1 '10 #9
semomaniz
210 Expert 100+
as i said earlier you will have to rebind the datagrid in you button click event and add the empty check code below the databinding.
Mar 1 '10 #10
Hallo Semo,

i did like that semo but still no output. here is my code
Expand|Select|Wrap|Line Numbers
  1. [Protected Sub btnSuchen_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSuchen.Click
  2.         dlErgebnis.DataBind()
  3.         If dlErgebnis.Items.Count <= 0 Then
  4.             lbdata.Visible = True
  5.             lbdata.Text = "Keine datei"
  6.         Else
  7.             lbdata.Visible = False
  8.         End If
  9.     End Sub 
thank you
Mar 1 '10 #11
semomaniz
210 Expert 100+
where is the datasource to bind the datalist?
Mar 1 '10 #12
Hallo Semo,

I Datasource i use the DatasetTableAdapter in the asp datasource tag as shown below

Expand|Select|Wrap|Line Numbers
  1. <asp:ObjectDataSource ID="ObjectDataSource1" runat="server" OldValuesParameterFormatString="original_{0}"
  2.             SelectMethod="GetData" TypeName="DataSetComplianceTableAdapters.DataTable1TableAdapter">
  3.             <SelectParameters>
  4.                 <asp:ControlParameter ControlID="tbSuchstring" Name="SLL_SPL_NAME1" PropertyName="Text"
  5.                     Type="String" />
  6.             </SelectParameters>
  7.         </asp:ObjectDataSource>
Thank you.
Mar 2 '10 #13
semomaniz
210 Expert 100+
You will also have to define the data source on your button click event for it to update.
Mar 2 '10 #14
wayko
1
bool.parse is a c command
boolean.parse is the vb equivalent
Aug 7 '13 #15

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Rimu Atkinson | last post by:
hi all i use FindControl to get a textbox, and i get a textbox object, but it's ..Text property is empty. some background info: i have a DataList, which has a template column in it, and in...
1
by: j_ruez | last post by:
I have looked everywhere and honestly can't believe I am the only one trying to figure this out. Maybe I am searching under the wrong keywords. I have a datalist. It is bound to an array, but...
0
by: Mark Sandfox | last post by:
What I need to do is simple in any other code, but I am having a problem finding the correct syntax for this function. I have the following: <form Runat="Server">
4
by: mahsa | last post by:
hi I want to use a check box in datalist when user checked the check box price will be shown in the textbox in the same row in datalist do you have any idea <input onclick="test()"...
1
by: Luis Ferrao | last post by:
Hi, i'm experiencing strange problems with the datalist webcontrol. I have it bound to a datatable like this: Me.TreeNodeList.DataSource = _existingNodesTable Me.TreeNodeList.DataBind() ...
1
by: Nathan Sokalski | last post by:
I have a DataList with a RepeatColumns property that has a value of 3. However, when the number of items is not divisible by 3, I have blank cells at the end of the list, which makes the DataList...
6
by: Paul | last post by:
I am trying to use a DataList and the ItemTemplate. I am binding the Datalist to a SQL query that gives me a list of Items with a Parent Category. I want to loop through all the items, but...
15
by: mosipenko | last post by:
I used to have a problem with DBNull, but now my issue is: System.InvalidOperationException: Invalid attempt to read when no data is present Here's my code behind: Private Sub...
0
by: rafiki31 | last post by:
I have the following problem. I just learned how to use datalist with repeatcolumns. The thing is that when i fill the Datalist with information from the DB there are some columns that dont have...
1
parshupooja
by: parshupooja | last post by:
Hi All, I am working in ASP.NET C#. I have image folder in my application. I want to load all images in Gridview/datalist one column and second and third column with empty texboxes. I do not know...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.