Click here to Skip to main content
15,897,518 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hii i have a dropdownlist in gridview coloum.
I wants to add values in dropdownlist from database..!!
how can i do it?plzz tell me..
Gridview code is below??



C#
<asp:GridView ID="GridView2" runat="server" AutoGenerateColumns="False" 
                    DataSourceID="SqlDataSource1">
                    

<Columns> 
<asp:TemplateField HeaderText="Product_ID"> 
<ItemTemplate> 
<asp:Label id="idlbl" runat="server" Text='<%#DataBinder.Eval(Container.DataItem,"id")%>' > 
</asp:Label> 
</ItemTemplate> 
</asp:TemplateField> 

<asp:TemplateField HeaderText="Product_Name"> 
<ItemTemplate> 
<asp:Label id="idlbl" runat="server" Text='<%#DataBinder.Eval(Container.DataItem,"id")%>' > 
</asp:Label> 
</ItemTemplate> 
</asp:TemplateField> 

<asp:TemplateField HeaderText="Product_Image"> 
<ItemTemplate> 
<asp:Label id="idlbl" runat="server" Text='<%#DataBinder.Eval(Container.DataItem,"id")%>' > 
</asp:Label> 
</ItemTemplate> 
</asp:TemplateField> 


<asp:TemplateField HeaderText="Product_Qty"> 
<ItemTemplate> 
<asp:DropDownList ID="ddl" runat ="server" DataTextField ="Product_Qty" DataValueField ="id" DataSourceID ="SqlDataSource1" > 
</asp:DropDownList> 
</ItemTemplate> 
</asp:TemplateField>

<asp:TemplateField HeaderText="Product_Rates"> 
<ItemTemplate> 
<asp:Label id="idlbl" runat="server" Text='<%#DataBinder.Eval(Container.DataItem,"id")%>' > 
</asp:Label> 
</ItemTemplate> 
</asp:TemplateField> 

</Columns>

</asp:GridView>




Database table is...below and i wants to add Product_Size Values into Dropdownlist.

CREATE TABLE [dbo].[Productmaster](
[product_Id] [int] IDENTITY(1,1) NOT NULL,
[product_Name] [nvarchar](max) NOT NULL,
[product_Image] [nvarchar](max) NOT NULL,
[product_Size] [int] NOT NULL,
[product_Rate] [int] NOT NULL,
CONSTRAINT [PK_Productmaster] PRIMARY KEY CLUSTERED
(
[product_Id] ASC
)
Posted

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