Solved

How do I Insert a blank row into a dropdownList

Posted on 2009-04-14
8
550 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
 

Author Comment

by:Projack
ID: 24142484
Please write this in c#.Net
0
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
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…

895 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now