Help me please;
I want to create and insert a simple (manual) dropdownlist in gridview (visual studio 2008 +sql server 2005), ddl to read 1,2,3,4,5 etc.

new to asp.net and nothing I've looked at makes sense so far.
ps, not to sharp with c# either.


if more detail required please read on....
The big picture; part of user-end shopping cart design - displaying database table (products) in gridview with a "manual" dropdownlist for user to select Quanity required (hence1,2,3,4,5 etc).

Thanks in advance.

There are a number of ways to do this; do you want a dynamic dropdown or is the data stored in it going to remain static and not expand? Here's a bit of code that goes in your Gridview for the dropdownlist:

<asp:TemplateField HeaderText="dropdownlist name" Visible="False">
<EditItemTemplate>
<asp:DropDownList ID="ddlName" runat="server" AppendDataBoundItems="true" DataSourceID="datasourcename" 
DataTextField="Keyfield" DataValueField="DataField" AutoPostBack="True" SelectedValue='<%# Eval("fieldname") %>'>
<asp:ListItem Value="">Select Number</asp:ListItem>
</asp:DropDownList>
</EditItemTemplate>
<ItemTemplate>
<asp:DropDownList ID="ddlName1" runat="server" AppendDataBoundItems="true" DataSourceID="datasource"  DataTextField="key" DataValueField="data" AutoPostBack="True" SelectedValue='<%# Eval("fieldname") %>'>
<asp:ListItem Value="">Select Number</asp:ListItem>
</asp:DropDownList>	
</ItemTemplate>
</asp:TemplateField>

This shows the code for both the EditItem and the ListItem. Let me know if you need a better explanation of it, but if you go to your ASP code for the GridView, it should have this code (or at least part of it) of course you will have to change the names of the fields and datasource to use yours, but I hope this helps.

Coleen

I sort of get whats happening but what do I do if I want to create a manual dropdownlist that displays a dropdown menu of numbers within gridview.
These values are not a datasource
ie. 1
2
3
4
however every other column within the gridview is connected to a sqldatasource

ps. dont mean to be exasperating

use
ddlName.Item.Add("1")
ddlName.Item.Add("2")
ddlName.Item.Add("3")
ddlName.Item.Add("4")

in your page load in your code-behind (this is VB.Net - I'm not sure how to do it in C#, but I'm sure it's similar)

HTH,

Hi

am new to programming and .Net...i want a dropdownlist in my gridview control..i am using vb..CAN YOU PLEASE GUIDE ME HOW TO GET DATA IN DROPDOWN LIST...

THANKS
RAHUL


There are a number of ways to do this; do you want a dynamic dropdown or is the data stored in it going to remain static and not expand? Here's a bit of code that goes in your Gridview for the dropdownlist:

<asp:TemplateField HeaderText="dropdownlist name" Visible="False">
<EditItemTemplate>
<asp:DropDownList ID="ddlName" runat="server" AppendDataBoundItems="true" DataSourceID="datasourcename" 
DataTextField="Keyfield" DataValueField="DataField" AutoPostBack="True" SelectedValue='<%# Eval("fieldname") %>'>
<asp:ListItem Value="">Select Number</asp:ListItem>
</asp:DropDownList>
</EditItemTemplate>
<ItemTemplate>
<asp:DropDownList ID="ddlName1" runat="server" AppendDataBoundItems="true" DataSourceID="datasource"  DataTextField="key" DataValueField="data" AutoPostBack="True" SelectedValue='<%# Eval("fieldname") %>'>
<asp:ListItem Value="">Select Number</asp:ListItem>
</asp:DropDownList>	
</ItemTemplate>
</asp:TemplateField>

This shows the code for both the EditItem and the ListItem. Let me know if you need a better explanation of it, but if you go to your ASP code for the GridView, it should have this code (or at least part of it) of course you will have to change the names of the fields and datasource to use yours, but I hope this helps.

Coleen

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.