• Visitors can check out the Forum FAQ by clicking this link. You have to register before you can post: click the REGISTER link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. View our Forum Privacy Policy.
  • Want to receive the latest contracting news and advice straight to your inbox? Sign up to the ContractorUK newsletter here. Every sign up will also be entered into a draw to WIN £100 Amazon vouchers!

GridView dot net question

Collapse
X
  •  
  • Filter
  • Time
  • Show
Clear All
new posts

    #11
    Originally posted by DimPrawn View Post
    You are just propogating a bad design.

    Create a class to represent the data. Create a constructor that will consume your mad array of strings. Bind the grid to a List<T> of these objects.

    Don't pass the array around your application. Get it into nice objects ASAP.
    I agree. However this has become more of an intellectual challenge now. Clearly a datatable would do.

    I think I will have to go this one alone. If I find something out I will post back here.

    Edit : It was only because I was asked, and did not know the answer that made me go looking. I would of course use good application design if I had the authority. "Tread lightly" was the advice in a recent thread.
    Knock first as I might be balancing my chakras.

    Comment


      #12
      I don't think that you will get the data binding to work against a multi-dimensional array. However, you could always change the code to

      <asp:TextBox id=blah runat="server text='<%# RenderMyField() %>'


      with RenderMyField in the Code Behind as

      protected String RenderMyField()
      {

      return ((Object)this.GetDataItem()).ToString();

      }

      Put a breakpoint onto the line with the return on it and see what type it shows as. It will probably be a multidimensional array, in which case you could explicitly refer to the fields as

      return (String)((String[])this.GetDataItem())[0];

      Comment


        #13
        Originally posted by Weltchy View Post



        return (String)((String[])this.GetDataItem())[0];
        I'm sure the next person who has to extend the code will love you for all of this.

        Comment


          #14
          Originally posted by Weltchy View Post
          I don't think that you will get the data binding to work against a multi-dimensional array. However, you could always change the code to

          <asp:TextBox id=blah runat="server text='<%# RenderMyField() %>'


          with RenderMyField in the Code Behind as

          protected String RenderMyField()
          {

          return ((Object)this.GetDataItem()).ToString();

          }

          Put a breakpoint onto the line with the return on it and see what type it shows as. It will probably be a multidimensional array, in which case you could explicitly refer to the fields as

          return (String)((String[])this.GetDataItem())[0];
          Spot on Weltchy. That then made me think of casting the Container.Item to a (string[]) which compiles ok.

          In the page load however,

          this line breaks

          gvLeagueTable.DataBind();

          With the error "Array was not a one-dimensional array."

          So it looks to be like it cannot be done.
          Knock first as I might be balancing my chakras.

          Comment


            #15
            Originally posted by DimPrawn View Post
            You are just propogating a bad design.

            Create a class to represent the data. Create a constructor that will consume your mad array of strings. Bind the grid to a List<T> of these objects.

            Don't pass the array around your application. Get it into nice objects ASAP.
            Shush DP. Remember, unmaintainable and impossible to read code leads to longer as well as return contracts.

            Note - This of course relies on the client being thick as two short planks!!!

            Comment


              #16
              Originally posted by Weltchy View Post
              Shush DP. Remember, unmaintainable and impossible to read code leads to longer as well as return contracts.

              Note - This of course relies on the client being thick as two short planks!!!
              I see a lot of code that looks like this going to India to be further mangled as the cost of maintaining nasty badly designed spaghetti in the UK is too high.

              Comment


                #17
                Originally posted by DimPrawn View Post
                I see a lot of code that looks like this going to India to be further mangled as the cost of maintaining nasty badly designed spaghetti in the UK is too high.
                Ah, good point.

                return (String)((String[])this.GetDataItem())[0];

                once its been indianized, would convert to

                return (((System.String)(((System.String)(((System.String )((System.String)((System.String[])((System.Object)this.GetDataItem()))[0])));

                With maybe a comment such as,

                /// Convert field To System String from String Array instance value, working very well, nicely yes!!!!

                Comment


                  #18
                  Originally posted by suityou01 View Post
                  Edit : "Tread lightly" was the advice in a recent thread.
                  This thread is painful. This problem should have been solved within minutes by just creating a class to deal with it. I don't think I could face being in a contract where I had to tread so lightly that I could not produce a 20 line class in order to save hours of messing around trying to get a gridview to go against everything C# is all about.

                  I have had people ask me in the past about how to manage things using multi-dimensional arrays as they wish to save time in writing classes. I tell them you don't and this thread is a fine example on why you will not save anytime using them.

                  Comment


                    #19
                    Originally posted by DimPrawn View Post
                    I see a lot of code that looks like this going to India to be further mangled as the cost of maintaining nasty badly designed spaghetti in the UK is too high.
                    In all seriousness though, writing code like this is just being plain lazy.

                    Comment


                      #20
                      Originally posted by Jaws View Post
                      This thread is painful. This problem should have been solved within minutes by just creating a class to deal with it. I don't think I could face being in a contract where I had to tread so lightly that I could not produce a 20 line class in order to save hours of messing around trying to get a gridview to go against everything C# is all about.

                      I have had people ask me in the past about how to manage things using multi-dimensional arrays as they wish to save time in writing classes. I tell them you don't and this thread is a fine example on why you will not save anytime using them.
                      Yes, you start your contract and at about five weeks in the penny drops that the nested 14th dimension element in the array is the persons DOB.

                      And then you wonder why you don't get renewed when you've only managed to fix three bugs in the 3 months.

                      Comment

                      Working...
                      X