GridView

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • ata@mailinator.com

    GridView

    Hi folks,
    Consider a gridview that's being bound to a ObjectDataSourc e that uses
    an adapter to handle data access logic.

    1. How am I supposed to have a RowIndex column *without* modifying the
    Entity class?
    2. How am I supposed to assign a given TAG object to each row?

    Any help would be highly appreciated,

    Thanks
    Jack
  • Mark Rae [MVP]

    #2
    Re: GridView

    <ata@mailinator .comwrote in message
    news:38694e80-884e-4a8b-83d0-a4c17c4afa25@m3 g2000hsc.google groups.com...
    1. How am I supposed to have a RowIndex column *without* modifying the
    Entity class?
    Firstly, you're not "supposed to" have a RowIndex column - there's no law
    that says you have to have one...

    However, it's easy enough:

    1) Add a template field to your existing GridView:

    <asp:TemplateFi eld HeaderText="Row Index">
    <ItemTemplate >
    <asp:Label ID="lblRowIndws " runat="server" />
    </ItemTemplate>
    </asp:TemplateFie ld>

    2) Wire up a RowDataBound event to your GridView if it doesn't already have
    one:


    3) Add the following code to the RowDataBound event:

    protected void gvResults_RowDa taBound(object sender, GridViewRowEven tArgs e)
    {
    if (e.Row.RowType == DataControlRowT ype.DataRow)
    {
    e.Row.Cells[0].Text = e.Row.RowIndex. ToString();
    //e.Row.Cells[6].Text = (Convert.ToInt3 2(e.Row.RowInde x) +
    1).ToString();
    }
    }

    Remember to modify the cell indexer accordingly...

    2. How am I supposed to assign a given TAG object to each row?
    Can you please explain what you mean by "given TAG object"...?


    --
    Mark Rae
    ASP.NET MVP


    Comment

    • ata@mailinator.com

      #3
      Re: GridView

      On Jun 1, 3:26 pm, "Mark Rae [MVP]" <m...@markNOSPA Mrae.netwrote:
      <a...@mailinato r.comwrote in message
      >
      news:38694e80-884e-4a8b-83d0-a4c17c4afa25@m3 g2000hsc.google groups.com...
      >
      1. How am I supposed to have a RowIndex column *without* modifying the
      Entity class?
      >
      Firstly, you're not "supposed to" have a RowIndex column - there's no law
      that says you have to have one...
      >
      However, it's easy enough:
      >
      1) Add a template field to your existing GridView:
      >
      <asp:TemplateFi eld HeaderText="Row Index">
      <ItemTemplate >
      <asp:Label ID="lblRowIndws " runat="server" />
      </ItemTemplate>
      </asp:TemplateFie ld>
      >
      2) Wire up a RowDataBound event to your GridView if it doesn't already have
      one:http://msdn.microsoft.com/en-us/libr...ebcontrols.gri...
      >
      3) Add the following code to the RowDataBound event:
      >
      protected void gvResults_RowDa taBound(object sender, GridViewRowEven tArgs e)
      {
      if (e.Row.RowType == DataControlRowT ype.DataRow)
      {
      e.Row.Cells[0].Text = e.Row.RowIndex. ToString();
      //e.Row.Cells[6].Text = (Convert.ToInt3 2(e.Row.RowInde x) +
      1).ToString();
      }
      >
      }
      >
      Remember to modify the cell indexer accordingly...
      >
      2. How am I supposed to assign a given TAG object to each row?
      >
      Can you please explain what you mean by "given TAG object"...?
      >
      --
      Mark Rae
      ASP.NET MVPhttp://www.markrae.net
      I need to store the Entity Object (for future references) associated
      with each row.

      Comment

      • Mark Rae [MVP]

        #4
        Re: GridView

        <ata@mailinator .comwrote in message
        news:35505624-bc0b-4886-92ef-454fdcde9ff2@d1 g2000hsg.google groups.com...
        I need to store the Entity Object (for future references) associated
        with each row.
        And did my response not work for you...?


        --
        Mark Rae
        ASP.NET MVP


        Comment

        • ata@mailinator.com

          #5
          Re: GridView

          On Jun 1, 3:52 pm, "Mark Rae [MVP]" <m...@markNOSPA Mrae.netwrote:
          <a...@mailinato r.comwrote in message
          >
          news:35505624-bc0b-4886-92ef-454fdcde9ff2@d1 g2000hsg.google groups.com...
          >
          I need to store the Entity Object (for future references) associated
          with each row.
          >
          And did my response not work for you...?
          >
          --
          Mark Rae
          ASP.NET MVPhttp://www.markrae.net
          Of course, the first problem (RowIndex) will be solved as you
          described.
          However, I still need to store an Object for every single row. How's
          this possible?

          Comment

          • Mark Rae [MVP]

            #6
            Re: GridView

            <ata@mailinator .comwrote in message
            news:9838e640-95b7-4e29-8e44-5c826b3073de@z6 6g2000hsc.googl egroups.com...
            However, I still need to store an Object for every single row. How's
            this possible?
            What sort of object is it? What does it look like? Is it plain text? If not,
            can it be serialised?
            Remember that a GridView is just an HTML table by the time it gets rendered
            to the browser...

            Is it not possible to retrieve this object in some other way so that you
            don't need to actually squirt it down to the browser? Maybe via the
            Gridview's underlying data source...?


            --
            Mark Rae
            ASP.NET MVP


            Comment

            • ata@mailinator.com

              #7
              Re: GridView

              On Jun 1, 4:17 pm, "Mark Rae [MVP]" <m...@markNOSPA Mrae.netwrote:
              <a...@mailinato r.comwrote in message
              >
              news:9838e640-95b7-4e29-8e44-5c826b3073de@z6 6g2000hsc.googl egroups.com...
              >
              However, I still need to store an Object for every single row. How's
              this possible?
              >
              What sort of object is it? What does it look like? Is it plain text? If not,
              can it be serialised?
              Remember that a GridView is just an HTML table by the time it gets rendered
              to the browser...
              >
              Is it not possible to retrieve this object in some other way so that you
              don't need to actually squirt it down to the browser? Maybe via the
              Gridview's underlying data source...?
              >
              --
              Mark Rae
              ASP.NET MVPhttp://www.markrae.net
              Well, let's say it's an Employee object, that can be actually binary
              serialized (because of different circumstances I've got).
              I need to have the actual object graph that's being associated with
              each row for update/delete operations.

              As far as I understood, I've to serialize the object graph to base-64,
              and keep it as an invisible row info.
              That's ok so far.

              However, I've got no idea how to retrieve the base-64 string back when
              deleting/updating a given record.

              Any help would be highly appreciated,

              Thanks a lot.

              Comment

              • Mark Rae [MVP]

                #8
                Re: GridView

                <ata@mailinator .comwrote in message
                news:013588fa-dc3b-4d7e-bb7c-fdf058ae5f05@d1 g2000hsg.google groups.com...
                Well, let's say it's an Employee object, that can be actually binary
                serialized (because of different circumstances I've got).
                I need to have the actual object graph that's being associated with
                each row for update/delete operations.
                But why do you need to actually send the entire serialised Employee object
                down to the client browser for this? What purpose can it possibly serve
                there...? You're presumably using a postback to do the update and delete
                operations, no...? Is each Employee not identified by a unique identifier?


                --
                Mark Rae
                ASP.NET MVP


                Comment

                • ata@mailinator.com

                  #9
                  Re: GridView

                  On Jun 1, 7:20 pm, "Mark Rae [MVP]" <m...@markNOSPA Mrae.netwrote:
                  <a...@mailinato r.comwrote in message
                  >
                  news:013588fa-dc3b-4d7e-bb7c-fdf058ae5f05@d1 g2000hsg.google groups.com...
                  >
                  Well, let's say it's an Employee object, that can be actually binary
                  serialized (because of different circumstances I've got).
                  I need to have the actual object graph that's being associated with
                  each row for update/delete operations.
                  >
                  But why do you need to actually send the entire serialised Employee object
                  down to the client browser for this? What purpose can it possibly serve
                  there...? You're presumably using a postback to do the update and delete
                  operations, no...? Is each Employee not identified by a unique identifier?
                  >
                  --
                  Mark Rae
                  ASP.NET MVPhttp://www.markrae.net
                  Of course, an employee record is identified by a single Identifier.
                  But we've got a mechanism to control the concurrency which actually
                  forces me to send back the object graph to the service layer, either
                  for modification or for deletion.

                  Is this applicable? Thanks.

                  Comment

                  • Mark Rae [MVP]

                    #10
                    Re: GridView

                    <ata@mailinator .comwrote in message
                    news:cb1c7954-9003-4563-9195-8616077c8364@26 g2000hsk.google groups.com...
                    Of course, an employee record is identified by a single Identifier.
                    But we've got a mechanism to control the concurrency which actually
                    forces me to send back the object graph to the service layer, either
                    for modification or for deletion.
                    But I *still* can't see why you need to store the entire object
                    client-side... :-)

                    Why can't you just store the unique Employee identifier? Then, during
                    postback, retrieve the unique Employee identifier from the row being
                    modified, construct an Employee object out of it, and then do whatever you
                    need to do with it...


                    --
                    Mark Rae
                    ASP.NET MVP


                    Comment

                    • ata@mailinator.com

                      #11
                      Re: GridView

                      On Jun 1, 7:36 pm, "Mark Rae [MVP]" <m...@markNOSPA Mrae.netwrote:
                      <a...@mailinato r.comwrote in message
                      >
                      news:cb1c7954-9003-4563-9195-8616077c8364@26 g2000hsk.google groups.com...
                      >
                      Of course, an employee record is identified by a single Identifier.
                      But we've got a mechanism to control the concurrency which actually
                      forces me to send back the object graph to the service layer, either
                      for modification or for deletion.
                      >
                      But I *still* can't see why you need to store the entire object
                      client-side... :-)
                      >
                      Why can't you just store the unique Employee identifier? Then, during
                      postback, retrieve the unique Employee identifier from the row being
                      modified, construct an Employee object out of it, and then do whatever you
                      need to do with it...
                      >
                      --
                      Mark Rae
                      ASP.NET MVPhttp://www.markrae.net
                      Well, it takes a long time to describe things. Would you please
                      let me know how to access an invisible cell value, while removing a
                      given row?

                      Comment

                      • Mark Rae [MVP]

                        #12
                        Re: GridView

                        <ata@mailinator .comwrote in message
                        news:eea3442f-c064-486b-9560-62a6e6469b27@a7 0g2000hsh.googl egroups.com...
                        Would you please let me know how to access an invisible cell value,
                        while removing a given row?
                        Depends how you "hide" it... If you set a column's Visible property to
                        false, then it won't even get rendered to the client browser, so that won't
                        help you here.

                        However, a much better method involves the DataKeys property of the
                        DataGrid - set it to the Employee ID and then you can retrieve it easily on
                        postback:
                        Gets a collection of DataKey objects that represent the data key value of each row in a GridView control.



                        --
                        Mark Rae
                        ASP.NET MVP


                        Comment

                        • ata@mailinator.com

                          #13
                          Re: GridView

                          On Jun 1, 8:08 pm, "Mark Rae [MVP]" <m...@markNOSPA Mrae.netwrote:
                          <a...@mailinato r.comwrote in message
                          >
                          news:eea3442f-c064-486b-9560-62a6e6469b27@a7 0g2000hsh.googl egroups.com...
                          >
                          Would you please let me know how to access an invisible cell value,
                          while removing a given row?
                          >
                          Depends how you "hide" it... If you set a column's Visible property to
                          false, then it won't even get rendered to the client browser, so that won't
                          help you here.
                          >
                          However, a much better method involves the DataKeys property of the
                          DataGrid - set it to the Employee ID and then you can retrieve it easily on
                          postback:http://msdn.microsoft.com/en-us/libr...ebcontrols.gri...
                          >
                          --
                          Mark Rae
                          ASP.NET MVPhttp://www.markrae.net
                          OK, I'm convinced that your solution is really reasonable. So I'm
                          trying to fix
                          my thoughts... I've just set the DataKeyNames to Id and ChangeStamp as
                          you
                          already mentioned.

                          I'm trying to remove the record by it's ID/ChangeStamp pairs, however,
                          the DeleteEmployee
                          method gets called twice and it's really annoying. The first time,
                          it's actually removed, I swear!
                          So why the runtime system calls the function for the second time? :)

                          Thank you really for your time
                          Jack

                          Comment

                          • Mark Rae [MVP]

                            #14
                            Re: GridView

                            <ata@mailinator .comwrote in message
                            news:6b92c5dc-6783-4ac6-89a2-f090c3e4ba1b@k1 3g2000hse.googl egroups.com...
                            I'm trying to remove the record by its ID/ChangeStamp pairs, however,
                            the DeleteEmployee method gets called twice and it's really annoying. The
                            first time, it's actually removed, I swear!
                            So why the runtime system calls the function for the second time? :)
                            Have you tried stepping through the code...?


                            --
                            Mark Rae
                            ASP.NET MVP


                            Comment

                            • ata@mailinator.com

                              #15
                              Re: GridView

                              On Jun 1, 8:31 pm, "Mark Rae [MVP]" <m...@markNOSPA Mrae.netwrote:
                              <a...@mailinato r.comwrote in message
                              >
                              news:6b92c5dc-6783-4ac6-89a2-f090c3e4ba1b@k1 3g2000hse.googl egroups.com...
                              >
                              I'm trying to remove the record by its ID/ChangeStamp pairs, however,
                              the DeleteEmployee method gets called twice and it's really annoying. The
                              first time, it's actually removed, I swear!
                              So why the runtime system calls the function for the second time? :)
                              >
                              Have you tried stepping through the code...?
                              >
                              --
                              Mark Rae
                              ASP.NET MVPhttp://www.markrae.net
                              The problem I'm referring to is actually posted here.


                              However, the workaround posted there actually doesn't work!
                              Any idea?

                              Comment

                              Working...