How to move a row in a data table object to the top of the table? The data table is in a data set. The data is bound to a drop down list box.

I am maintaining some 2003 C#/asp.net code for a web application. In the application a table in a data set is used
to populate a drop down list box.(The drop down list box will display a list of names)

Before the data set table is bound to the list box control, blank characters are inserted at the top
of the data set table. The purpose of this, is to display a blank line in the drop down list box, when the list box is
initially displayed. This code works fine. (See lines 1-14 below).

Now I have been asked to modify the source code so that instead of a blank line being inserted at to top of the
list box, the name "Molbors" is displayed as the first item in the list. Meaning "Molbors" will be the first item
displayed in the drop down listbox when the web form is initially displayed.

The problem here is that "Molbors" already exists in the data set table. And since the data set table is sorted alphabetically,
"Molbors" is in about the middle of the data set table. So my question is how do I move the row containing "Molbors" to the very top of the data
set table? Meaning how do I make it become the first row in the data set table?

Here is the code I am currently using:


1 // This method populates the drop down list.
2 public static DropDownList BindBuyerSeller(DropDownList dropDownList)
3 {
4 //Connect to "BID" Reference Data Web Service
5  BIDReferenceWS.BIDReferenceDataWebService myBIDReferenceService = new BIDReferenceWS.BIDReferenceDataWebService();
6  BIDReferenceWS.BIDReferenceDS BIDReferenceDS = myBIDReferenceService.getAllSellerBuyers(); // Call the webservice to populate the data set
7 //BIDReferenceDS is the data set. It contains a data table named "Owner". Owner contains two columns. One named
8 // OwnerName, and the other named PropertyDescription.
9 //  
10//Insert a blankline at the top of the dataset. So blanks will be the default value for the drop down list box.
11  BIDReferenceWS.BIDReferenceDS.OwnerRow blankOwnerRow = BIDReferenceDS.Owner.NewOwnerRow();
12  blankOwnerRow.OwnerDescription = "";
13 // On the next line we insert the blank row at the top of the "Owner" table.
14  BIDReferenceDS.Owner.Rows.InsertAt(blankOwnerRow,0);

0
AppDevForMe
2/6/2007 7:29:59 PM
asp.net.web-forms 93655 articles. 6 followers. Follow

3 Replies
1742 Views

Similar Articles

[PageSpeed] 10
Get it on Google Play
Get it on Apple App Store

Could you  programatically select "Molbors" and achieve the effect you need?

If you have a function hooked up to the control, you may need to disable it while you do the selection.

A cheesy way to do it is to stick a leading space in front of " Molbors" so it sorts to the top.


Steve Wellens

My blog
0
SGWellens
2/6/2007 7:45:59 PM

 

 You offered some good ideas for shortcuts, thank you for that. The shortcuts won't work though for this problem. The requirements are that I move "Molbors" to the top of the list, as well as making it the default vaule.

So if anyone knows how I can move the value "Molbors" to the top of the list, please help me. This must be done somehow by moving the data row of the data table object to the very first row.

 

 

0
AppDevForMe
2/7/2007 6:42:15 PM
Hi, 
here is a solution for you:

DataTable dt = ds.Tables[0];
object[] array = dt.Rows[1].ItemArray; // the fixed index 1 should be changed to the index of the item Molbors
DataRow row = dt.Rows[1];
dt.Rows.Remove(row);

row = dt.NewRow();
row.ItemArray = array;
dt.Rows.InsertAt(row, 0);

Hope it helps.

0
Raymond
2/8/2007 4:06:26 AM
Reply:

Similar Artilces:

Adding Rows from different Data table to a single Data Table
Hi, I have 3 data tables say dt1, dt2, dt3. None of the tables have any relation with each other. Now i my requirement is to merge all these 3 datatables into 1.  But, i dont want it into different rows. Means to say, record from 1st, 2nd and 3rd table shud be merged as a single row in resultant datatable. Below example explains better Table 1 : 123 abc 890 Table 2 : rew 234 Table 3: sdfsd 234 dfg 45645 Now Resultant table shud be :  123 abc 890 rew 234 sdfsd 234 dfg 45645 Any help is appreciated :) Thanks in advance   If you keep your feet firmly on ...

to fetch data gridview data into a data table
Hi I have one gridview. which have some textboxes and some are data boud columns. I want to fetch whole the data in the gridview into one data set or datatable.And then insert that dataset or datatable into one other database table. Is there any way to do that. Please reply as soon as possible at max_ashu@yahoo.com and ashish.gautam@rbs.com  regards Ashish Gautam Hi, >>"...and some are data boud columns..."  Where does the original data on the GridView come from? From you words, seems that it also from a DataSet? If so, you can save the input values ...

data, data, data
Hello, I need some advice on the best method to keep a database updated in this scenario. I have a local Solomon SQL Server where we keep our inventory. I want to build an application that will be hosted at a remote hosting location which provides a SQL database. I want to build the application to allow clients to access the inventory items and make requests based on the remote SQL data. The order will be sent to our fulfillment department via email; they will fiill the request and ship.  I'm not sure the method to do this while keeping the data current on the remote and the l...

Data row from a Data Table
Hi All, I have a method which returns all the rows to a DataTable.  So from that Data Table I want a particular Row whose values should be assigned to text boxes on the webpage. Please can any help me out on how to do this ? Thanks for your time..   // assuming that you want the first row DataRow r=dataTable1.Rows[0]; TextBox1.Text=r["Column1"]; TextBox2.Text=r["Column2"];  Regards,Anas Ghanem.Note:Please Don't hesitate to click "Report Abuse" link if you noticed something wrong on the forums (like duplicate ,Off-topic,offensiv...

How to select data from a table and insert the selected data in the same table as new row
Hi    I have a table called Version and its attributes are Version_ID, Project_ID , Hospital_ ID , Date_Created and comments. I want to select the data by Version_ID,Project_ID and  Hospital_ID and the selected data is inserted in the same table(Version) as new row . Table: Version (Version_ID(Primary_key), Project_ID(Foreign_Key),Hospital_ID(Foreign_Key),Date_Created,Comments).  Iam using Visual Web Developer Express 2005 and SQL Server 2005. Iam doing on asp.net 2.0. Could anyone please send me the code in asp.net 2.0 for the above problem. ...

query data from data table object
Hi, Is there any way to query data from datatabel object like this: "select distinct columnName"? i have a method which return datatable from excel sheet, i want to manpulate the inoforrmation before i save them to the database i know i can use the select method for a datatbale, but it seems that it just play the role of the 'Where' condition any help please Thanks   ,  HiYes, there is way to get select distinct columns from DataTable using Helper Class in Visual C# .NET. The following article will shed some light on this http://support.micros...

Data Set To Data Table basics
My overall objective is to build an excel or csv file from the onclick event of a button. In my button_click eventprotected void Button1_Click(object sender, EventArgs e) { BudgetYear budgetYear = (BudgetYear)Session["budgetYear"]; string fiscalyear = Convert.ToString(budgetYear.UserSelectedFiscalYear); int orgid = Convert.ToInt32(ddl_Orgs1.SelectedValue); DataSet dsOrginalExport = BmsDLL.GetOrginalExport(orgid, fiscalyear); }I assume since from what I've read I need to create a datatable to to export the data to a .xls or .csv?&...

populate data table with form data
This seems really dumb to have to post this, but I can't find an example of C# syntax for passing HTML form data into a DataTable...can anyone help?brad I don't have an example of this, but I do dynamically create a data table from an uploaded file. Relevant snippets to create the table, columns, and add data below. I'm just posting how to create the row and add data, this is not complete code.DataTable dt = new DataTable(); dt.TableName = tableName;foreach (Field metaField in fieldMetaData.fieldList.Values) { dt.Columns.Add(metaField.Name); } DataRow row = dt.NewRow();f...

How to set user who can't modify any StoredProc and data in Tables but can read data in Tables and any StoredProc ?
Please give me advise ครับ   Go into Management Studio, connect to your database and go to Security-->Users from the treeview. Right click and select New User. Create the use based on the relevant login and then go to the Securables option where you can add tables and stored procedures and select which rights the user will have.Website Design Darlington - http://mdssolutions.co.ukhttp://lessthandot.com - Experts, Information, Ideas & Knowledgehttp://aspnetlibrary.com - An online resource for professional ASP.NET developersPlease remember to click "Mark as Answer" o...

Select data from sourse table to insert to destination table and then delete those data ?
Hello everyone , I need to do something with Sql server 2005 from visual studio 2008. I have two tables in the database names students , Temporarilystudents : My question is how I can select specifics data from temporarilystudents table and insert those data to Students table and after that delete those data from temporarily table. Can you please give me the SQL Statement to achieve functionality? Actions Speaks Loader than words insert into Students select * from TempStudents drop table TempStudents. Or insert into Students select * from TempStudents where my conditions delete fr...

Data Table/Data Grid
Hi, I have a "survey results" page located here: http://www.airsep.net/forms/surveyresults.aspx I need to do two things. 1) Have the "Mean" column round to the nearest 10th and display a 0 when it is a whole number 2) When the user selects percent, I would like a percent symbol displayed next to each number. Here is my code so far: Sub CalculateSubmissions(ByVal Type As Integer) 'Type - 1)Percentage ' 2)Numbers Dim dt As New DataTable Dim question(13) As String question(1) = "How would you rate the accessibility of our Customer Se...

how to fetch the data from data table
hi,  i am new to dotnet. can u please help me in fetching the data from database and  returns the data table? reply soon thanking you  Hi, Welcome to asp.net forums. Check the code below to return a datatable. The code has been taken from here. protected void DataTable returnData() { // Declare your connection string called strConnection assuming you use sql   string connectionString =      "server=localhost;database=Northwind;uid=sa;pwd=sa";    // create a SqlConnectio...

Data Reader or Data Table
Hello .. When to use DataReader and when to use DataTable, which is faster and which is preffered   Thank youPlease remember to "Mark As Answer" if this post answered your question!Bilal Shouman - MCAD.NET|My Blog|---------------------------------  The behavior of a DataReader and DataTable is very different, so there is no preferred solution.A DataReader retrieves its data from an open database connection and while it's open it won't allow any other interaction with the same connection. It is the most "close to the core" way of getting data from th...

how delete a 1 row data in data table?
hi ! i know this is a newbie type of question! Im afraid! anyone knows how delete a 1 row data in data table? thanks in advanced!practice makes perfect but nobody is perfect so why practice! You can remove a row one of two ways. DataTable.Remove(DataRow)DataTable.RemoveAt(Index) HTH,RyanRyan OlshanASPInsider | Microsoft MVP, ASP.NEThttp://ryanolshan.comHow to ask a question...

Web resources about - How to move a row in a data table object to the top of the table? The data table is in a data set. The data is bound to a drop down list box. - asp.net.web-forms

Object database - Wikipedia, the free encyclopedia
When database capabilities are combined with object-oriented programming language capabilities, the result is an object-oriented database management ...

Objects that helped shape Australians of the Year on display at National Museum of Australia
... a marker pen, binoculars, a cricket bat, a family photograph, a skin "cassette" and a painting by a death-row prisoner. These are objects ... ...


Dolby Cinema: Twin laser projectors + object-based 3D audio = awesome
... by simply adding more channels. Instead, it allows sounds to be dynamically placed in a 3D space. This is used to great effect when noisy objects ...

Divers pull objects from lake in San Bernardino investigation - Videos - CBS News
In a murky lake, divers looking for clues pulled what looked like a CD or DVD out of the water. The lake is less than three miles from the Inland ...

IBM Launches Object Storage on Bluemix
IBM Object Storage, a new service on Bluemix, enables developers to simply and securely store and access growing volumes of unstructured data. ...

MIT's Amazing New App Lets You Program Any Object
... AR app that makes programming your smart home as easy as connecting the dots. The end goal of the Internet of Things is to make every object ...

Astronomers Find New Object, Possible Super-Earth In Our Solar System
A potential super-Earth could lurk on the outer edge of our solar system.

Facebook user identifies mysterious gold object found in Israel cemetery
Facebook user identifies mysterious gold object found in Israel cemetery

Seattle mayor objects to Uber union legislation, declines to sign bill and asks for changes
Seattle Mayor Ed Murray refused to sign a new law his council unanimously approved on Monday that will give Uber, Lyft, taxi, and other for-hire ...

Resources last updated: 12/29/2015 12:58:35 AM