GridView with nested Combobox


Jul 15, 2011
Programming Experience
Hello to all readers.
(Dont know if this should go here or under ASP.Net seeing its VB.Net i posted it here)

You have a store and like to order a couple of new items for your store, so naturally you will need an order form to be filled in.

Requirements on the form are:
ID number of the product (IcnNumber)
Product description

When the form loads ONLY ONE datagrid row must be visible with the controls combobox (IcnNumber flied), label(description label) and textbox (quantity field). Then a button is clicked to add a new row with the same controls as before that can be filled in by the user to order the items.

ASP.Net Code
<%@ Page Title="" Language="vb" AutoEventWireup="false" CodeBehind="WebForm1.aspx.vb"
    Inherits="WebApplication1.WebForm1" %>

<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="ajax" %>

<html xmlns="">
<head id="Head1" runat="server">
    <title>GridView RowDataBound Example</title>
    <form id="form1" runat="server">
    <asp:ScriptManager ID="ScriptManager1" runat="server">
    <asp:SqlDataSource ID="IcnDataSource" runat="server"></asp:SqlDataSource>
    <asp:UpdatePanel ID="udpOrder" runat="server" ChildrenAsTriggers="false" UpdateMode="Conditional">
            <asp:GridView ID="PersonGridView" runat="server" DataSourceID="IcnDataSource" AutoGenerateColumns="false"
                    <asp:TemplateField HeaderText="IcnNumber">
                            <ajax:ComboBox ID="cboIcnNumber" runat="server" />
                    <asp:TemplateField HeaderText="Description">
                            <asp:Label ID="lblDescription" runat="server" Text="Label"></asp:Label>
                    <asp:TemplateField HeaderText="Quantity">
                            <asp:TextBox ID="txtQuantity" runat="server" Width="30px"></asp:TextBox>

VB.Net Code Behind
Imports System.Configuration.ConfigurationManager
Imports AjaxControlToolkit

Public Class WebForm1
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        IcnDataSource.DataSourceMode = SqlDataSourceMode.DataReader
        IcnDataSource.ConnectionString = ConnectionStrings("PatientMISConnectionString").ConnectionString
        IcnDataSource.SelectCommand = "SELECT top(5) ItemId,IcnNumber FROM dbo.Items"
    End Sub

    Protected Sub OrderGridView_RowDataBound(ByVal sender As Object, ByVal e As GridViewRowEventArgs)
        Dim drdList As ComboBox
        For Each rowItem As GridViewRow In PersonGridView.Rows
            drdList = CType(rowItem.Cells(0).FindControl("cboIcnNumber"), ComboBox)
            drdList.DataSource = IcnDataSource
            drdList.DataTextField = "IcnNumber"
            drdList.DataValueField = "ItemId"
    End Sub
End Class

The problem
I have no idea on how to get ONLY ONE row visible to be filled in and the button ,can be any ware on the form, that can be click to add a new row.


I can get the combobox to populate and that is about all that I can do.

Now this is all done with ASP.Net, VB.Net, Visual Studio 2010, Framework 4 and
AJAX Control Toolkit - Download: 50401 version 4.1.50401

I have attached an .zip file ( that contains 2 files
1 x Preview.jpg = This is just to show what the result is from the above code

1 x WebForm1.aspx = just to help with the layout and not copy and past the code



    22.5 KB · Views: 25
Top Bottom