GridView Combobox HOW?

Widunder

Newcomer
Joined
Aug 3, 2010
Messages
10
Hello everyone,
I've spent hours searching through the Internet never finding anything relevant to my problem.
I've created a GridView, and populating it with the data from the SQL table. All working perfectly. What I do not understand is how to add a combobox next to each product. All I want in it is "1,2,3,4,5", nothing else, for quantity. I really do not want to make 5 fields in my table, just to store those numbers in. Because first of all, this will add too much redundancy in my data. Plus, what if I had 50 products?!?! Is there an easy way, just to make a combobox that next to each product with 1,2,3,4,5 in it. And then, from my code, refering to the selected number, through something like .SelectedIndex. Is that possible?! I just want to see some kind of example. I don't have errors related to that.
What I've tried is, treating it like php:

Code:
 <asp:TemplateField HeaderText="Qty" > 
         <EditItemTemplate> 
            <asp:DropDownList ID="DropDownQty" Runat="server" AppendDataBoundItems="true" DataSourceID="datasource"  DataTextField="key" DataValueField="data" AutoPostBack="True"> 
               <asp:ListItem Value="1">1</asp:ListItem> 
               <asp:ListItem Value="2">2</asp:ListItem> 
               <asp:ListItem Value="3">3</asp:ListItem> 
               <asp:ListItem Value="4">4</asp:ListItem>
               <asp:ListItem Value="5">5</asp:ListItem>  
            </asp:DropDownList>
         </EditItemTemplate> 
 
         </asp:TemplateField>

But this doesn't display anything except an empty column with "Qty" name on it.

Also in my code, when I go myGridView.Columns.Add( - its not giving me a combobox. A combobox also doesn't get displayed in the Smart Tag. When I try to add it through html it's not coming up with an error, but it's not displaying anything at the same time. When I try Dim combo As New DataGridViewComboBoxColumn - it says undefined

Thanks in advance.
Widunder.
 
Last edited:
Back
Top