Solved

How do I Insert a blank row into a dropdownList

Posted on 2009-04-14
8
549 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
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 
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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
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…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

746 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

9 Experts available now in Live!

Get 1:1 Help Now