check Empty DataList

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sarabonn
    New Member
    • Nov 2008
    • 69

    check Empty DataList

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

    Code:
    <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?
    Last edited by Frinavale; Mar 3 '10, 02:34 PM. Reason: Added code tags.
  • ThatThatGuy
    Recognized Expert Contributor
    • Jul 2009
    • 453

    #2
    Visible='<%#boo l.Parse((dlErge bnis.Items.Coun t==0) .ToString()) %>
    this is where you're commiting the biggest mistake....

    You can do the same via ternary operator like this
    Code:
    Visible='<%(dlErgebnis.Items.Count==0)?true:false;%>'>

    Correct me if i was wrong

    Comment

    • sarabonn
      New Member
      • Nov 2008
      • 69

      #3
      Hallo Thatthatguy ,

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

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

      Thank you .

      sarab

      Comment

      • semomaniz
        Recognized Expert New Member
        • Oct 2007
        • 210

        #4
        Try this

        Code:
        Visible='<%(dlErgebnis.Items.Count=0)?true:false;%>'>
        Remove one of the equals to sign, Count is and integer not string.

        Comment

        • sarabonn
          New Member
          • Nov 2008
          • 69

          #5
          Hallo Semomaniz,

          Thank you for your reply.. i tried that also but not successful..
          Last edited by sarabonn; Feb 26 '10, 02:57 PM. Reason: spelling mistake

          Comment

          • semomaniz
            Recognized Expert New Member
            • Oct 2007
            • 210

            #6
            Why dont you do this in a code behind?

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

            Code:
            If dlErgebnis.Items.Count= 0 then
               lblempty = "No data was found ";
            Also refer to this posting http://bytes.com/topic/asp-net/answe...empty-datalist

            Comment

            • sarabonn
              New Member
              • Nov 2008
              • 69

              #7
              Hallo semo,

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

              Code:
               dlErgebnis.DataBind()
                      If dlErgebnis.Items.Count <= 0 Then
                          lbdata.Visible = True
                          lbdata.Text = "Keine datei"
                      Else
                          lbdata.Visible = False
                      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..
              Last edited by Frinavale; Mar 3 '10, 02:35 PM. Reason: Please post code in [code] ... [/code] tags. Added code tags.

              Comment

              • semomaniz
                Recognized Expert New Member
                • Oct 2007
                • 210

                #8
                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.

                Comment

                • sarabonn
                  New Member
                  • Nov 2008
                  • 69

                  #9
                  Hallo Semo,

                  This my aspx code.
                  Code:
                  <div id="Eingabe" runat="server">
                          <p>Firma oder Person: </p>
                          <asp:TextBox ID="tbSuchstring" width="400px" runat="server" />
                          <asp:Button ID="btnSuchen" runat="server" Text="Suchen" />
                          <asp:CustomValidator ID="CVtbSuchstring" runat="server" OnServerValidate="CVtbSuchstring_ServerValidate" />
                  
                      </div>
                    
                      <div id="Ergebnis" runat="server">
                          <asp:DataList ID="dlErgebnis"  runat="server" DataSourceID="ObjectDataSource1">
                              <ItemTemplate>
                                  Liste: <asp:Label ID="SLL_SPL_LIST_TYPELabel" runat="server" Text='<%# Eval("SLL_SPL_LIST_TYPE") %>' />
                                  <b><asp:Label ID="SLL_SPL_LAW1" runat="server" Text='<%# Eval("SLL_SPL_LAW1") %>' /></b>
                                  - Eintrag vom <asp:Label ID="SLL_SPL_ENTRY_DATE" runat="server" Text='<%# Eval("SLL_SPL_ENTRY_DATE", "{0:d}") %>' /><br />
                                  <asp:Label ID="SLL_SPL_NAME1Label" runat="server" Text='<%# Eval("SLL_SPL_NAME1") %>' />
                                  <asp:Label ID="SLL_SPL_NAME2Label" runat="server" Text='<%# Eval("SLL_SPL_NAME2") %>' /><br />
                                  <asp:Label ID="SLL_SPL_STREETLabel" runat="server" Text='<%# Eval("SLL_SPL_STREET") %>' />
                                  <asp:Label ID="SLL_SPL_HOUSE_NUMBERLabel" runat="server" Text='<%# Eval("SLL_SPL_HOUSE_NUMBER") %>' /><br />
                                  <asp:Label ID="SLL_SPL_CITYLabel" runat="server" Text='<%# Eval("SLL_SPL_CITY") %>' />
                                  <asp:Label ID="SLL_SPL_DISTRICTLabel" runat="server" Text='<%# Eval("SLL_SPL_DISTRICT") %>' /><br />
                                  <br />
                                  <br />
                                  </ItemTemplate>
                                 <FooterTemplate>
                                 </FooterTemplate>
                             </asp:DataList>
                          <asp:ObjectDataSource ID="ObjectDataSource1" runat="server" OldValuesParameterFormatString="original_{0}"
                              SelectMethod="GetData" TypeName="DataSetComplianceTableAdapters.DataTable1TableAdapter">
                              <SelectParameters>
                                  <asp:ControlParameter ControlID="tbSuchstring" Name="SLL_SPL_NAME1" PropertyName="Text"
                                      Type="String" />
                              </SelectParameters>
                          </asp:ObjectDataSource>
                          
                      </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.
                  Last edited by Frinavale; Mar 3 '10, 02:32 PM. Reason: Please post code in [code] ... [/code] tags. Added code tags.

                  Comment

                  • semomaniz
                    Recognized Expert New Member
                    • Oct 2007
                    • 210

                    #10
                    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.

                    Comment

                    • sarabonn
                      New Member
                      • Nov 2008
                      • 69

                      #11
                      Hallo Semo,

                      i did like that semo but still no output. here is my code
                      Code:
                      [Protected Sub btnSuchen_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSuchen.Click
                              dlErgebnis.DataBind()
                              If dlErgebnis.Items.Count <= 0 Then
                                  lbdata.Visible = True
                                  lbdata.Text = "Keine datei"
                              Else
                                  lbdata.Visible = False
                              End If
                          End Sub
                      thank you
                      Last edited by Frinavale; Mar 3 '10, 02:33 PM. Reason: Please post code in [code] ... [/code] tags. Added code tags.

                      Comment

                      • semomaniz
                        Recognized Expert New Member
                        • Oct 2007
                        • 210

                        #12
                        where is the datasource to bind the datalist?

                        Comment

                        • sarabonn
                          New Member
                          • Nov 2008
                          • 69

                          #13
                          Hallo Semo,

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

                          Code:
                          <asp:ObjectDataSource ID="ObjectDataSource1" runat="server" OldValuesParameterFormatString="original_{0}"
                                      SelectMethod="GetData" TypeName="DataSetComplianceTableAdapters.DataTable1TableAdapter">
                                      <SelectParameters>
                                          <asp:ControlParameter ControlID="tbSuchstring" Name="SLL_SPL_NAME1" PropertyName="Text"
                                              Type="String" />
                                      </SelectParameters>
                                  </asp:ObjectDataSource>
                          Thank you.
                          Last edited by Frinavale; Mar 3 '10, 02:33 PM. Reason: Please post code in [code] ... [/code] tags. Added code tags.

                          Comment

                          • semomaniz
                            Recognized Expert New Member
                            • Oct 2007
                            • 210

                            #14
                            You will also have to define the data source on your button click event for it to update.

                            Comment

                            • wayko
                              New Member
                              • Aug 2013
                              • 1

                              #15
                              bool.parse is a c command
                              boolean.parse is the vb equivalent

                              Comment

                              Working...