Solved

How do I Insert a blank row into a dropdownList

Posted on 2009-04-14
8
554 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
Technology Partners: 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!

 

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

Guide to Performance: Optimization & Monitoring

Nowadays, monitoring is a mixture of tools, systems, and codes—making it a very complex process. And with this complexity, comes variables for failure. Get DZone’s new Guide to Performance to learn how to proactively find these variables and solve them before a disruption occurs.

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…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
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…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

685 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