convert listview.datasource to datatable

Posted by Kumarsudu under C# on 7/18/2012 | Points: 10 | Views : 8628 | Status : [Member] | Replies : 2
Hi All,

I am trying to convert listview.datasource to datatable.

The datasource is populating but when i am assigning as below
say some menu control
empMenu.DataSource = listview.DataSource as datatable; // here i am getting listview.DataSource as null.
empMenu.DataBind();

Please guide me.

Regards,
Kumar




Responses

Posted by: Ranjeet_8 on: 7/18/2012 [Member] [MVP] Gold | Points: 25

Up
0
Down
Try like this.

DataTable dt = new DataTable();

foreach (ListViewItem item in listView1.Items)
{
table.Columns.Add(item.ToString()); //For adding column names
foreach (var it in item.SubItems) //For adding row values
dt.Rows.Add(it.ToString());
}


Kumarsudu, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Dotnetrajanikanth on: 7/18/2012 [Member] Starter | Points: 25

Up
0
Down
Ensure that the page is not posting back again.

Try enableviewstate = false

____________
www.flickr.com/photos/psdesigner/

Kumarsudu, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response