Datalist loadtemplate

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,
I'm trying to create a page with a datalist that loads from a template the
ItemTemplate, which contains a linkbutton that should have the commandname =
"edit"
But when I click on the link button nothing happens. I tried also the
findcontrol method, without any result.

That's the template:

<asp:LinkButton ID="button1" Runat="server" Text=''
CommandName="Edit" >
<asp:Label id="Label2" runat="server"
Text='<%#DataBinder.Eval(Container, "DataItem.CPNAME"%>'>

that's the code to load the template:

DataSet _eve = loaddata();

this.DataList1.ItemTemplate = Page.LoadTemplate("templa1.ASCX");

DataList1.DataSource= _eve;

DataList1.DataBind();


then i also tried this one ::

foreach(DataListItem item in DataList1.Items)

{

LinkButton _li = new LinkButton();

_li = (LinkButton)item.FindControl("button1");

_li.Text="Hello" ; ////// HERE IS NOT WORKING , GIVES ME AN ERROR ON
REFERENCE TO OBJECT NOT SET ON AN ISTANCE

When i click on the LinkButton i should be able to call the editcommand
routine, but nothing happens, is because the template is loaded in a
different way than the control?
Thank you
Fabrizio
 
Fabrizo:

It's hard to see a complete picutre with the snippets of code, but are
you loading the template on every pot back? Do you have an event
handler defined for the edit event? Is it wired up to the EditCommand
event of the DataList?
 
Yes I do load the template every postback and the EditCommand event of the
Datalist is seems ok. I would like to know why loading the itemtemplate with
the loadtemplate method is different than having a datalist with the
itemtemplate defined at design time.
Do you have any suggestion?
 
I'll have to try some experiments, offhand I don't know where there
would be a difference.
 
Back
Top