Solved

How do I Insert a blank row into a dropdownList

Posted on 2009-04-14
8
553 Views
Last Modified: 2013-12-17
stored proccedure
Create PROCEDURE [dbo].[adm_GetCustomerName]
      
AS
select Distinct Customer_name
from CUSTOMERS

// code foe binding
 private void BindName()
        {
            // CatalogAccess.GetDepartments returns a DataTable object containing
            // department data, which is read in the ItemTemplate of the DataList
            ddlCustomerName.DataSource = customerLogs.GetCustomerName();
            // Needed to bind the data bound controls to the data source
            ddlCustomerName.DataTextField = "Customer_Name";
            //ddlCustomerName.DataValueField = "Customer_id";
            ddlCustomerName.DataBind();
        }



// code foe binding
 private void BindName()
        {
            // CatalogAccess.GetDepartments returns a DataTable object containing
            // department data, which is read in the ItemTemplate of the DataList
            ddlCustomerName.DataSource = customerLogs.GetCustomerName();
            // Needed to bind the data bound controls to the data source
            ddlCustomerName.DataTextField = "Customer_Name";
            //ddlCustomerName.DataValueField = "Customer_id";
            ddlCustomerName.DataBind();
        }

Open in new window

0
Comment
Question by:Projack
8 Comments
 
LVL 12

Expert Comment

by:needo_jee
ID: 24142339
dim item as new listItem(" ","  ")
listbox.items.insert(0,item)

thanks
0
 
LVL 12

Expert Comment

by:needo_jee
ID: 24142353

'after this line ddlCustomerName.DataBind();

dim li as new listItem(" ","  ")
ddlCustomerName.items.insert(0,li)

-thanks

0
 
LVL 12

Expert Comment

by:needo_jee
ID: 24142393
depending on your need you may use above or following method

instead adding to listbox.. you may add to your table and then bind to list


after
dim dt as datatable = customerLogs.GetCustomerName()

dt.rows.insert(0,"","")

perform binding here ...

-thanks
0
How Do You Stack Up Against Your Peers?

With today’s modern enterprise so dependent on digital infrastructures, the impact of major incidents has increased dramatically. Grab the report now to gain insight into how your organization ranks against your peers and learn best-in-class strategies to resolve incidents.

 

Author Comment

by:Projack
ID: 24142484
Please write this in c#.Net
0
 
LVL 6

Expert Comment

by:SaedSalman
ID: 24143205
what about DropDownList1.Items.Add("");
0
 
LVL 6

Expert Comment

by:SaedSalman
ID: 24143268
Also you can use: ListItem x= new ListItem("", "");
0
 
LVL 12

Expert Comment

by:needo_jee
ID: 24144944
private void BindName()
        {
            // CatalogAccess.GetDepartments returns a DataTable object containing
            // department data, which is read in the ItemTemplate of the DataList
            ddlCustomerName.DataSource = customerLogs.GetCustomerName();
            // Needed to bind the data bound controls to the data source
            ddlCustomerName.DataTextField = "Customer_Name";
            //ddlCustomerName.DataValueField = "Customer_id";
            ddlCustomerName.DataBind();

ListItem li=new ListItem("", "");

ddlCustomerName.Items.Insert(0,li);


        }

I have used insert instead of Items.Add because most likely the blank item will be required at 0 index.
if you want to insert a blank item at the end of exiting items then you should use
ddlCustomerName.Items.Add(li);
OR
ddlCustomerName.Items.Add(new ListITem("",""));

-Thanks
0
 
LVL 8

Accepted Solution

by:
ppittle earned 500 total points
ID: 24151485
The above are all correct solutions.  This my personal preferance:

<%-- DataSource specified and DataBind() called in code-behind --%>
                    <asp:DropDownList ID="ddlCustomerName" runat="server" AppendDataBoundItems="true">
                        <asp:ListItem Text="Select One..." Value="" />
                    </asp:DropDownList>
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

861 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