+ Reply to Thread
Results 1 to 7 of 7

Thread: Accessing controls in the Footer of a datalist

  1. #1
    Administrator richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich's Avatar
    Join Date
    Mar 2008
    Location
    Somewhere only we know...
    Posts
    3,207
    Blog Entries
    14
    Real Name
    Rich
    Rep Power
    14

    Accessing controls in the Footer of a datalist

    Is it possible to access controls within a datalist footer on postback?

    It seems bizarre to me that when you do an OnItemDataBound on a datalist control the header and footer are included, but when you do a postback the datalist.items property doesn't include them?

    I have several textbox and dropdowns that I need to access and I can't.

    Any ideas anyone?

  2. #2
    The Barnfather jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead's Avatar
    Join Date
    Mar 2008
    Location
    Reston, VA
    Posts
    4,547
    Blog Entries
    9
    Real Name
    Jason
    Rep Power
    22

    Try following this example:

    Code:
    Private Sub datalist1_ItemDataBound(ByVal sender As Object, ByVal e As DataItemEventArgs) 
        If e.Item.ItemType = ItemType.Footer Then 
            Dim l As Label = DirectCast(e.Cells(0).Controls("labelname"), Label) 
            l.Text = "New Text" 
        End If 
    End Sub
    
    jmurrayhead
    If you agree, give me rep.
    If you like it here...throw us a few bones to help support us.


  3. #3
    Administrator richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich's Avatar
    Join Date
    Mar 2008
    Location
    Somewhere only we know...
    Posts
    3,207
    Blog Entries
    14
    Real Name
    Rich
    Rep Power
    14

    Referencing it OnItemDataBound isn't a problem.

    But, I have textboxes and dropdowns that I need to reference on postback.

    I can't think of a way to refer to the footer. It's not included in datalist.items and isn't a control in it's own right.

    It just seems crazy that they've overlooked this, so wondered if anyone knew any different?
    Quote Originally Posted by MSDN
    Note:
    Only items bound to the data source are contained in the Items collection. The header, footer and seperator are not included in the collection.
    Looks like I'll have to rethink this then...

  4. #4
    The Barnfather jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead's Avatar
    Join Date
    Mar 2008
    Location
    Reston, VA
    Posts
    4,547
    Blog Entries
    9
    Real Name
    Jason
    Rep Power
    22

    Well, you'll have to use a different event then. See here for a list of events supported by the DataList:

    DataList Events (System.Web.UI.WebControls)
    jmurrayhead
    If you agree, give me rep.
    If you like it here...throw us a few bones to help support us.


  5. #5
    Administrator richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich's Avatar
    Join Date
    Mar 2008
    Location
    Somewhere only we know...
    Posts
    3,207
    Blog Entries
    14
    Real Name
    Rich
    Rep Power
    14

    The postback is not being fired by a button inside the datalist, so I can't add an event to it.

    Basically I have a whole page of Policy Information. Part of this is a datalist containing details of the premiums.

    The details of each premium can be changed and when the Page level Update button control is clicked it cycles through each of the datalist items and checks for any updates.

    What I wanted to do was have the ability to Add a premium to the list, so I included this in the footer of the datalist. You click an Add button within the footer of the datalist and the various dropdown and textbox controls are shown in the footer.

    Once these are completed, the user clicks the Page level Update button control and what I thought would happen was the footer would be included in the datalist.items collection and I could grab the details from the controls inside the footer and add them to the db. That way I could easily differentiate between an existing premium and a new one.

    Hope that makes sense. Can you think of a way to achieve this?

    I'm wondering if instead of including the details in the footer, I could Add an item to the datalist and have the Add details in this. What do you think?

    <edit>Actually, I guess another option would be to have an "Add" button at the end of the footer, which the user has to click to add the new premium. Would I then be able to access the various controls, if the button firing the event is also in the footer?</edit>
    Last edited by richyrich; May 12th, 2008 at 11:58 AM.

  6. #6
    The Barnfather jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead's Avatar
    Join Date
    Mar 2008
    Location
    Reston, VA
    Posts
    4,547
    Blog Entries
    9
    Real Name
    Jason
    Rep Power
    22

    Yeap, this sounds a lot like the issue with using GridViews. Users not only want the ability to to edit/delete items, they wanted to be able to insert new items (see here: Adding an insert row to GridView)

    This might give you an idea on how to handle the DataList.

    EDIT::

    Here's an example using a DataList: http://www.dotnetspider.com/forum/Vi...ForumId=128096
    jmurrayhead
    If you agree, give me rep.
    If you like it here...throw us a few bones to help support us.


  7. #7
    Administrator richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich's Avatar
    Join Date
    Mar 2008
    Location
    Somewhere only we know...
    Posts
    3,207
    Blog Entries
    14
    Real Name
    Rich
    Rep Power
    14

    I managed to solve the problem.

    I included an "Add" button at the end of the footer section and gave it an Edit commandname which fires code to retrieve the controls using the DataListCommandEventArgs and then adds the details to the database.

    I then just get it to rebuild the datalist control.

    Just means users have to click a seperate button to add the premium....Not a bad thing, really.

    Booya!!

+ Reply to Thread

Similar Threads

  1. Finding Datalist Row on auto postback
    By richyrich in forum .NET Development
    Replies: 1
    Last Post: May 12th, 2008, 05:52 AM
  2. add additional footer to gridview
    By peebman2000 in forum .NET Development
    Replies: 13
    Last Post: May 2nd, 2008, 02:50 PM
  3. Accessing skmmenu control in Master Page
    By richyrich in forum .NET Development
    Replies: 13
    Last Post: March 18th, 2008, 12:45 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

SEO by vBSEO