Accessing items in EmptyDataTemplate

7 posts, 0 answers
  1. James
    James avatar
    4 posts
    Member since:
    Sep 2010

    Posted 03 Sep 2010 Link to this post

    Am trying to access a control in the emptydata item template to disable it for certain users. My template looks like this:

    <EmptyDataTemplate>
     
         This staff member currently has no blogs.
     
         <br />
     
         <asp:LinkButton ID="lnkBtnAddBlog" runat="server" CommandName="AddBlog"
                 Visible="<%# AllowUserEdits() %>"> Add new blog</asp:LinkButton>
     
     </EmptyDataTemplate>

    The function in the "visible" attribute isn't firing, yet the exact same button is in the Item template and it fires ok there.

    I also can't find a FindControl function for the empty item in code..but i can for the other templates.

    So how would i go about accessing that control?

    Many thanks

    James
  2. Rosen
    Admin
    Rosen avatar
    3234 posts

    Posted 08 Sep 2010 Link to this post

    Hi James,

    You may consider using the Load event of the LinkButton to set its visibility instead.

    Greetings,
    Rosen
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. James
    James avatar
    4 posts
    Member since:
    Sep 2010

    Posted 08 Sep 2010 Link to this post

    Hi,

    Thanks for the reply. I'd never thought of the Load event for the control itself, that seems a smart idea.
    For the time being I moved my control below the listview and dealt with it there instead as it's position wasn't vital.

    So there's no equivalent of FindControl for empty templates?

    Thanks,

    James :-)
  5. Rosen
    Admin
    Rosen avatar
    3234 posts

    Posted 08 Sep 2010 Link to this post

    Hello James,

    Indeed, you can use FindControl to get reference to the LinkButton, by hooking to ItemCreated event, similar to the following:

    protected void RadListView1_ItemCreated(object sender, Telerik.Web.UI.RadListViewItemEventArgs e)
    {
        if (e.Item is RadListViewEmptyDataItem)
        {
            Debug.Assert(e.Item.FindControl("lnkBtnAddBlog") != null);            
        }
    }


    Greetings,
    Rosen
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  6. James
    James avatar
    4 posts
    Member since:
    Sep 2010

    Posted 08 Sep 2010 Link to this post

    Thanks very much again.. That would do the trick I think.. I'm still just getting used to the control :-)

    I wonder if there would be a way in future to do it like with the other templates:
    RadListViewStaffBlog.InsertItem.FindControl("----")

    One further question regarding the ItemCreated event.. or the ItemDataBound.
    How would one get the value of the datakey from these events?

    Thanks for all the help, much appreciated.

    James :-)
  7. Rosen
    Admin
    Rosen avatar
    3234 posts

    Posted 08 Sep 2010 Link to this post

    Hello James,

    You may use RadListViewDataItem GetDataKeyValue method:

    protected void RadListView1_ItemDataBound(object sender, Telerik.Web.UI.RadListViewItemEventArgs e)
    {
        var dataItem = e.Item as RadListViewDataItem;
        if (dataItem != null)
        {
            //MyDataKeyName should be declared through RadListView's DataKeyNames property
            var value = (int)dataItem.GetDataKeyValue("MyDataKeyName");
        }
    }


    Regards,
    Rosen
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  8. James
    James avatar
    4 posts
    Member since:
    Sep 2010

    Posted 08 Sep 2010 Link to this post

    Thanks a lot, that's just what i needed.. Really appreciate the help! :D
    Just a case of finding all the new method names :-)
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017