Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Foor loop Code Block in ASPX Page

Foor loop Code Block in ASPX Page

Scheduled Pinned Locked Moved ASP.NET
helpxmlarchitecturecareer
8 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Ma tju
    wrote on last edited by
    #1

    Hi guys, I got little problem here. I cannot get the value for ColName. Below are my code

    <tr ondblclick="job_detail('<%#Eval("id")%>');" >
    <td width="15"><input name="Checkbox51" type="checkbox" style=" width:13px; height:13px;" value="<%#Eval("id")%>" /></td>
    <%
    For j = 0 To countCol - 1
    Response.Write("<td width=" & colSize(j) & ">" & Eval(colName(j)) & "</td>")
    Next
    %>
    </tr>

    It give me an error : Databinding methods such as Eval(), XPath(), and Bind() can only be used in the context of a databound control. Can someone help me. Thanks in advance. matju

    ma tju Software Application Engineer Petaling Jaya,Selangor, Malaysia Ring Master SB MVP 2008 ;p Petaling Jaya MOP (Otai)

    G 1 Reply Last reply
    0
    • M Ma tju

      Hi guys, I got little problem here. I cannot get the value for ColName. Below are my code

      <tr ondblclick="job_detail('<%#Eval("id")%>');" >
      <td width="15"><input name="Checkbox51" type="checkbox" style=" width:13px; height:13px;" value="<%#Eval("id")%>" /></td>
      <%
      For j = 0 To countCol - 1
      Response.Write("<td width=" & colSize(j) & ">" & Eval(colName(j)) & "</td>")
      Next
      %>
      </tr>

      It give me an error : Databinding methods such as Eval(), XPath(), and Bind() can only be used in the context of a databound control. Can someone help me. Thanks in advance. matju

      ma tju Software Application Engineer Petaling Jaya,Selangor, Malaysia Ring Master SB MVP 2008 ;p Petaling Jaya MOP (Otai)

      G Offline
      G Offline
      geeeeeeeetha
      wrote on last edited by
      #2

      hi, Just remove eval from Response.Write("<td width=" & colSize(j) & ">" & colName(j) & "</td>") this line. Hope it 'll help u Thanks

      M 1 Reply Last reply
      0
      • G geeeeeeeetha

        hi, Just remove eval from Response.Write("<td width=" & colSize(j) & ">" & colName(j) & "</td>") this line. Hope it 'll help u Thanks

        M Offline
        M Offline
        Ma tju
        wrote on last edited by
        #3

        Hi, Actually i need to use Eval to bind the data from datasource. But to use eval I need to include the '#' sign.

        ma tju Software Application Engineer Petaling Jaya,Selangor, Malaysia Ring Master SB MVP 2008 ;p Petaling Jaya MOP (Otai)

        K 1 Reply Last reply
        0
        • M Ma tju

          Hi, Actually i need to use Eval to bind the data from datasource. But to use eval I need to include the '#' sign.

          ma tju Software Application Engineer Petaling Jaya,Selangor, Malaysia Ring Master SB MVP 2008 ;p Petaling Jaya MOP (Otai)

          K Offline
          K Offline
          keyur satyadev
          wrote on last edited by
          #4

          can you put the code that how you bind the datasource?

          Regards Keyur Satyadev

          M 1 Reply Last reply
          0
          • K keyur satyadev

            can you put the code that how you bind the datasource?

            Regards Keyur Satyadev

            M Offline
            M Offline
            Ma tju
            wrote on last edited by
            #5

            Sure, here is the code.

                Dim conn As New         SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings(0).ConnectionString)
                Dim sqlDA As New SqlDataAdapter("SELECT id, filename, img\_size FROM image ORDER BY id", conn)
                Dim ds As New DataSet
                Dim pgDataSrc As New PagedDataSource
                Try
                    sqlDA.Fill(ds, "tl")
            
                    pgDataSrc.DataSource = ds.Tables("tl").DefaultView
                    pgDataSrc.AllowPaging = True
                    pgDataSrc.PageSize = 20
                    pgDataSrc.CurrentPageIndex = CurrentPage
            
                    'rptInbox is a repeater control
                    rptInbox.DataSource = pgDataSrc
                    rptInbox.DataBind()
            
                Catch ex As Exception
                    Return False
                Finally
                    conn = Nothing
                    sqlDA = Nothing
                    ds = Nothing
                End Try
            

            Well sometimes user want to see just 1 or more column in the repeater. Thats why i use for loop to generate the column. Hope this help. Thanks in advance.

            ma tju Software Application Engineer Petaling Jaya,Selangor, Malaysia Ring Master SB MVP 2008 ;p Petaling Jaya MOP (Otai)

            K 1 Reply Last reply
            0
            • M Ma tju

              Sure, here is the code.

                  Dim conn As New         SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings(0).ConnectionString)
                  Dim sqlDA As New SqlDataAdapter("SELECT id, filename, img\_size FROM image ORDER BY id", conn)
                  Dim ds As New DataSet
                  Dim pgDataSrc As New PagedDataSource
                  Try
                      sqlDA.Fill(ds, "tl")
              
                      pgDataSrc.DataSource = ds.Tables("tl").DefaultView
                      pgDataSrc.AllowPaging = True
                      pgDataSrc.PageSize = 20
                      pgDataSrc.CurrentPageIndex = CurrentPage
              
                      'rptInbox is a repeater control
                      rptInbox.DataSource = pgDataSrc
                      rptInbox.DataBind()
              
                  Catch ex As Exception
                      Return False
                  Finally
                      conn = Nothing
                      sqlDA = Nothing
                      ds = Nothing
                  End Try
              

              Well sometimes user want to see just 1 or more column in the repeater. Thats why i use for loop to generate the column. Hope this help. Thanks in advance.

              ma tju Software Application Engineer Petaling Jaya,Selangor, Malaysia Ring Master SB MVP 2008 ;p Petaling Jaya MOP (Otai)

              K Offline
              K Offline
              keyur satyadev
              wrote on last edited by
              #6

              why should you write the response.write here as bind function only work with control. you can use just Databinder.Eval() or simply Eval() as it your repeater control you get all the values. for more specify your exact need to writing the response.write as its just give the message.

              Regards Keyur Satyadev

              M 1 Reply Last reply
              0
              • K keyur satyadev

                why should you write the response.write here as bind function only work with control. you can use just Databinder.Eval() or simply Eval() as it your repeater control you get all the values. for more specify your exact need to writing the response.write as its just give the message.

                Regards Keyur Satyadev

                M Offline
                M Offline
                Ma tju
                wrote on last edited by
                #7

                Actually I try to do this:

                <%
                For j = 0 To countCol - 1
                'during loop it will skip this line. This is why I use response.write.
                <td width=<%#(colSize(j))%>><%#Eval(colName(j))%></td>
                Next
                %>

                but when it loops it will skip the code in the for loop. When i use response.write it will run line in for loop but return this error: Databinding methods such as Eval(), XPath(), and Bind() can only be used in the context of a databound control. Hope this help. Thanks in advanced.

                ma tju Software Application Engineer Petaling Jaya,Selangor, Malaysia Ring Master SB MVP 2008 ;p Petaling Jaya MOP (Otai)

                K 1 Reply Last reply
                0
                • M Ma tju

                  Actually I try to do this:

                  <%
                  For j = 0 To countCol - 1
                  'during loop it will skip this line. This is why I use response.write.
                  <td width=<%#(colSize(j))%>><%#Eval(colName(j))%></td>
                  Next
                  %>

                  but when it loops it will skip the code in the for loop. When i use response.write it will run line in for loop but return this error: Databinding methods such as Eval(), XPath(), and Bind() can only be used in the context of a databound control. Hope this help. Thanks in advanced.

                  ma tju Software Application Engineer Petaling Jaya,Selangor, Malaysia Ring Master SB MVP 2008 ;p Petaling Jaya MOP (Otai)

                  K Offline
                  K Offline
                  keyur satyadev
                  wrote on last edited by
                  #8

                  why you put the for loop as it is in the repeater. repeater will automatically manage this. it will returns for all the rows. can you more specify your exact requirement as what type of data you want to bind here?

                  Regards Keyur Satyadev

                  1 Reply Last reply
                  0
                  Reply
                  • Reply as topic
                  Log in to reply
                  • Oldest to Newest
                  • Newest to Oldest
                  • Most Votes


                  • Login

                  • Don't have an account? Register

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • World
                  • Users
                  • Groups