Click here to Skip to main content
15,028,757 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I bind data to dropdown list But when i am running the project datas are repetedely comining in the dropdown list...I need a help
My code:

XML
<asp:DropDownList ID="drpPurcahseBrand" runat="server" Height="24px"
                                       Width="173px" AppendDataBoundItems="True" AutoPostBack="True">
                                  <asp:ListItem Text="Select Brand" Selected="true"></asp:ListItem>
                                   </asp:DropDownList>


C#
drpPurcahseBrand.DataSource =                        ClassLibrary1.mainclass.dset("brand_name", "");
            drpPurcahseBrand.DataValueField = "Brand";
            drpPurcahseBrand.DataTextField = "Brand";
            DataBind();

Stored Procedure:
ALTER PROCEDURE brand_name
	
AS
	select Brand from Rate
	RETURN
Posted
Updated 11-Sep-14 20:46pm
v3
Comments
Prasad Avunoori 12-Sep-14 2:27am
   
Can you please post your code?
santoshkrpathak@gmail.com 12-Sep-14 2:31am
   
Please explain bit more or post some Example code
Bhavik_Patel 12-Sep-14 5:10am
   
your code is right...can you elaborate in which condition this problem comes? It may be you are calling dropdownlist binding method twice

Do this
before you bind Data.

C#
drpPurcahseBrand.Items.Clear()
   
drpPurcahseBrand.Items.Clear()
drpPurcahseBrand.DataValueField = "Brand";
drpPurcahseBrand.DataTextField = "Brand";
DataBind();

   
set AppendDataBoundItems="True" to false

and in code

C#
drpPurcahseBrand.DataValueField = "Brand";
            drpPurcahseBrand.DataTextField = "Brand";
            DataBind();
ListItem lst = new ListItem ( "Select Brand" , "0" );
drpPurcahseBrand.Items.Add(lst );
   
Set AppendDataBoundItems="False" else delete this. It will work.
   
remove return..

SQL
Stored Procedure:
ALTER PROCEDURE brand_name

AS
begin

    select Brand from Rate
end
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900