Solved

How do I Insert a blank row into a dropdownList

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

 

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

DevOps Toolchain Recommendations

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

Question has a verified solution.

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

Suggested Solutions

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
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…

770 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