I have datatable, from which a dataset is created by selecting all rows. after sorting the dataset based on one column, then I want to get first 5 rows and create a new dataset with the top 5 rows, how to do?
First of all, let me clear your concept about DataSet, DataTable and DataRow.
1. DataSet ( It is a collection of DataTables)
2. DataTable (It is a collection of DataRow)
3. DataRow (It is a collection of Data Elements)
Well, Now if you have a datatable, you cant create a DataSet from it... as basically it is already a part of a dataset. If you are talking about coping some rows from one DataTable to a new DataTable, this can be done. Just I am going to create an example for you below :
DataTable dtNew = dt.Clone();
var dataSelect = (from r in dt.AsEnumerable()
foreach (DataRow dr in dataSelect)
DataRow newRow = dtNew.NewRow();
for(int i=0; i<dr.Table.Columns.Count; i++)
newRow[dr.Table.Columns[i] = dr.Table.Columns[i];
After the foreach loop the DAtaTable dtNew will hold only the 5 elements selected in dataSelect.
Hope you got the point. Just mold this into your requirement.
Well... If the folder that contains the files is within your virtual directory path then you can use it directly.
But remember, This means you are going to open the link for everyone.. Anyone who doesnt have login even can download the file.
Rather than doing so, I like to have files in a secured folder (Say D:\secret) where my website is running in another path(say C:\MyWebSite), or rather files are in another file server which is within the same network say (\\server2\files)
Now when the user clicks on a link, the Onclick Event handler will transmit the file to the client using
I have an .ascx which contains a listview. Let's call it the parent.
Within its ItemTemplate I reference a second .ascx which is basically another listview, let's call it the child. On the parent, the child control is wrapped in a placeholder tag. I use this place holder tag to show and hide the child.
The child listview has a 'close' button in its Layout Template. Let's call it "btnClose" with an onClick event of "btnClose_Click". I want to use this button to set the visibility of the containing placeholder.
I'm trying to avoid doing something like using
PlaceHolder plhChild = (PlaceHolder)childListCtl.NamingContainer since I can't guarantee every instance of the child .ascx will be contained within a placeholder.
I tried creating an event in the child that could be subscribed to.
public delegate CloseButtonHandler();
public event CloseButtonHandler CloseButtonEvent;
And in the actual btnClose_Click(Object sender, EventArgs e) event I have:
if (CloseButtonEvent != null) CloseButtonEvent();
My problem is that the delegate CloseButtonEvent is always null.
I've tried assigning the delegate in the listview's OnDatabound event of the parent and on the click event that set's the plhChild.visible = true, and I've stepped through the code and know the delegate instantiation works in both place, but again, when it gets to the btnClose_Click event on the child, the delegate is null.
I've successfully loaded an XML file into a TreeView by using the XmlDataSource, which appears to be quite convenient. I can then add and remove items on the TreeView but having called the XmlDataSource.Save() method, my changes are not persisted to the file so when I bind the TreeView back to the XmlDataSource, I lose my changes.
1. I click the "Load" button which initiates the TreeView contents from the XML file by simply calling DataBind() on the TreeView.
2. I then add/edit/delete nodes using suitable buttons and my changes are reflected in the TreeView - that works fine.
3. I click the "Save" button.
I'd expect the XmlDataSource.Save() method to write my TreeView back to the bound data source. I've tried calling BindData() on the XmlDataSource itself but that does nothing.
I'd expect the XmlDataSource.Save() method to write my TreeView back to the bound data source.
I would ask you to check that if you are getting any exception while performing Save.
I was going through the MSDN [^]documentation of Save method, I found few points which you should consider as it can be used only for following scenarios -
1. The XML data is loaded from an XML file indicated by the DataFile property, not from inline XML data specified in the Data property.
2. No XSLT transformation is specified in the Transform or TransformFile properties.
Also, keep in mind Save does not handle concurrent scenario.