468,545 Members | 1,892 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,545 developers. It's quick & easy.

Datalist loadtemplate

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
Nov 16 '05 #1
3 3823
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?

--
Scott
http://www.OdeToCode.com/blogs/scott/

On Tue, 7 Dec 2004 07:53:04 -0800, "Fabrizio"
<Fa******@discussions.microsoft.com> wrote:
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


Nov 16 '05 #2
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?

"Scott Allen" wrote:
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?

--
Scott
http://www.OdeToCode.com/blogs/scott/

On Tue, 7 Dec 2004 07:53:04 -0800, "Fabrizio"
<Fa******@discussions.microsoft.com> wrote:
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


Nov 16 '05 #3
I'll have to try some experiments, offhand I don't know where there
would be a difference.

--
Scott
http://www.OdeToCode.com/blogs/scott/
On Tue, 7 Dec 2004 12:45:05 -0800, "Fabrizio"
<Fa******@discussions.microsoft.com> wrote:
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?

"Scott Allen" wrote:
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?

--
Scott
http://www.OdeToCode.com/blogs/scott/

On Tue, 7 Dec 2004 07:53:04 -0800, "Fabrizio"
<Fa******@discussions.microsoft.com> wrote:
>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
>



Nov 16 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Fabrizio | last post: by
1 post views Thread by Barry | last post: by
3 posts views Thread by Greg | last post: by
3 posts views Thread by mbailey | last post: by
reply views Thread by Antonio Carpentieri | last post: by
4 posts views Thread by Antonio Carpentieri | last post: by
3 posts views Thread by Mirek Endys | last post: by
reply views Thread by rioka | last post: by
reply views Thread by NPC403 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.