This is a migrated thread and some comments may be shown as answers.

Accessing items in EmptyDataTemplate

6 Answers 220 Views
ListView
This is a migrated thread and some comments may be shown as answers.
James
Top achievements
Rank 1
James asked on 03 Sep 2010, 03:33 PM
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

6 Answers, 1 is accepted

Sort by
0
Rosen
Telerik team
answered on 08 Sep 2010, 07:53 AM
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
0
James
Top achievements
Rank 1
answered on 08 Sep 2010, 09:39 AM
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 :-)
0
Rosen
Telerik team
answered on 08 Sep 2010, 11:14 AM
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
0
James
Top achievements
Rank 1
answered on 08 Sep 2010, 11:21 AM
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 :-)
0
Rosen
Telerik team
answered on 08 Sep 2010, 01:53 PM
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
0
James
Top achievements
Rank 1
answered on 08 Sep 2010, 01:56 PM
Thanks a lot, that's just what i needed.. Really appreciate the help! :D
Just a case of finding all the new method names :-)
Tags
ListView
Asked by
James
Top achievements
Rank 1
Answers by
Rosen
Telerik team
James
Top achievements
Rank 1
Share this question
or