Solved

Manually Add Row at start of Datatable

Posted on 2011-02-21
4
467 Views
Last Modified: 2012-06-27
I have a combobox on a form that I am filling by setting the Datasource Property. I want to be able to add a row to the start of the Datatable to display at the top of the combobox that has a 0 Value but instructs the user to select an Option ie: Select Customer....

I have managed to add a row to the datatable, but I don't know how to index it as the first row.

Thanks
Dim sCustomers As String = "SELECT * FROM tCustomers"
        Dim daCustomers As New SqlClient.SqlDataAdapter(sCustomers, myConn.sqlConn)
        daCustomers.Fill(dsCustomers, "dtCustomers")

        Dim newCustomersRow As DataRow = dsCustomers.Tables("dtCustomers").NewRow()
        newCustomersRow("ID") = "0"
        newCustomersRow("sName") = "Select Customer...."
        dsCustomers.Tables("dtCustomers").Rows.Add(newCustomersRow)

        cboCustomerName.DataSource = dsCustomers.Tables("dtCustomers")
        cboCustomerName.DisplayMember = "sName"
        cboCustomerName.ValueMember = "ID"

Open in new window

0
Comment
Question by:mgordon-spi
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 9

Accepted Solution

by:
rawinnlnx9 earned 500 total points
ID: 34947644
0
 
LVL 6

Expert Comment

by:AkAlan
ID: 34947715
Here is an example of how I do what you are asking. It is a function of the DropDownList more than doing it with your dataset. the AppendDataBoundItems is the important option to remember.

<asp:DropDownList ID="ddlSite" runat="server" Width="145px"  AppendDataBoundItems="true"  DataSourceID="sdsSite"
        DataTextField="SiteName" DataValueField="SiteID">
        <asp:ListItem Value="0">--Site--</asp:ListItem>
    </asp:DropDownList>
0
 

Author Comment

by:mgordon-spi
ID: 34947883
This is a vb form not a webpage. I can append quite easily in asp.net, but I am at a loss of how to do it with an Application
0
 

Author Comment

by:mgordon-spi
ID: 34947896
rawinnlnx9 that link did exactly what I needed it to.. Thank you
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question