How to create Listview Items in code

Feb 16, 2011 at 11:57 AM

Hi, nice tool for Ui.

So how can I created a new listview item in code behaind c#? see my code below, I used this in your sample example1.aspx in listview, but not work. why?

And If you have more samples using anothers components in code pls send, because I would like to used your components with datatable sqlserver.

thank you

using

OfficeWebUI.ListView;

namespace OfficeWebUITest.ListView

{ 

 

public partial class ListMode : System.Web.UI.Page

 { 

 

 protected void Page_Load(object sender, EventArgs e)

{

ListViewItem item = new ListViewItem();

item.Text ="Item 07";

item.ExtraText ="Descricao";

 

item.ImageUrl ="~/Img/docs.png";

 

 

this.ListView1.Items.Add(item);

}

}

}

 

Coordinator
Feb 16, 2011 at 8:35 PM

Hi,

Maybe the Page_Load() is a bit too late. Have you tried in the Init ?
Anyway, after having added the items to the listview, you can force the rebuild with the public "DataBind()" method.

Hope it helps.

SB

Feb 17, 2011 at 9:32 AM
Hello,
sb33.
Thanks about your anwers.
So if I put this code below in Init method not resolve the problem, the item 07 not appears in list ok.
but If I put Databind() method in Page_Load the item 07 now appear in list but duplicate the items list,
to more easy understand I send in attached image jpg with this error.
thanks again and waiting your response.
all code in page:

namespace

OfficeWebUITest.ListView{

public partial class ListMode : System.Web.UI.Page{

protected void Page_Init(object sender, EventArgs e){

ListViewItem item = new ListViewItem();

item.Text = "Item 07";

item.ExtraText = "Descricao";

item.ImageUrl = "~/Img/docs.png";

this.ListView1.Items.Add(item);

}

protected void Page_Load(object sender, EventArgs e)

{

this.ListView1.DataBind();

}

}

}

fyi


2011/2/16 sb33 <notifications@codeplex.com>

From: sb33

Hi,

Maybe the Page_Load() is a bit too late. Have you tried in the Init ?
Anyway, after having added the items to the listview, you can force the rebuild with the public "DataBind()" method.

Hope it helps.

SB

Read the full discussion online.

To add a post to this discussion, reply to this email (officewebui@discussions.codeplex.com)

To start a new discussion for this project, email officewebui@discussions.codeplex.com

You are receiving this email because you subscribed to this discussion on CodePlex. You can unsubscribe on CodePlex.com.

Please note: Images and attachments will be removed from emails. Any posts to this discussion will also be available online at CodePlex.com


Coordinator
Feb 19, 2011 at 11:50 AM

Yes, it sounds like a bug... I will have to fix it :)

Thanks for reporting

Coordinator
Mar 14, 2011 at 5:59 PM

Hi, it seems to work with the latest release. I put this code :

        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);

            ListViewItem item = new ListViewItem();
            item.Text = "Item 07";
            item.ExtraText = "Descricao";
            item.ImageUrl = "~/Img/docs.png";
            this.ListView1.Items.Add(item);

            this.ListView1.DataBind();

        }

And I have no duplicate anymore.

Hope it's ok for you

Sébastien

 

Mar 14, 2011 at 8:37 PM
Hello sb33,
I'll test this new release now and feed back to you.
Thank you

2011/3/14 sb33 <notifications@codeplex.com>

From: sb33

Hi, it seems to work with the latest release. I put this code :

        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);

            ListViewItem item = new ListViewItem();
            item.Text = "Item 07";
            item.ExtraText = "Descricao";
            item.ImageUrl = "~/Img/docs.png";
            this.ListView1.Items.Add(item);

            this.ListView1.DataBind();

        }

And I have no duplicate anymore.

Hope it's ok for you

Sébastien

Read the full discussion online.

To add a post to this discussion, reply to this email (officewebui@discussions.codeplex.com)

To start a new discussion for this project, email officewebui@discussions.codeplex.com

You are receiving this email because you subscribed to this discussion on CodePlex. You can unsubscribe on CodePlex.com.

Please note: Images and attachments will be removed from emails. Any posts to this discussion will also be available online at CodePlex.com