GridView with nested Combobox

Hav0c

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

Scenario:
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
Quantity

Desire:
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
VB.NET:
<%@ Page Title="" Language="vb" AutoEventWireup="false" CodeBehind="WebForm1.aspx.vb"
    Inherits="WebApplication1.WebForm1" %>

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

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title>GridView RowDataBound Example</title>
</head>
<body>
    <form id="form1" runat="server">
    <asp:ScriptManager ID="ScriptManager1" runat="server">
    </asp:ScriptManager>
    <asp:SqlDataSource ID="IcnDataSource" runat="server"></asp:SqlDataSource>
    <asp:UpdatePanel ID="udpOrder" runat="server" ChildrenAsTriggers="false" UpdateMode="Conditional">
        <ContentTemplate>
            <asp:GridView ID="PersonGridView" runat="server" DataSourceID="IcnDataSource" AutoGenerateColumns="false"
                OnRowDataBound="OrderGridView_RowDataBound">
                <Columns>
                    <asp:TemplateField HeaderText="IcnNumber">
                        <ItemTemplate>
                            <ajax:ComboBox ID="cboIcnNumber" runat="server" />
                        </ItemTemplate>
                    </asp:TemplateField>
                    <asp:TemplateField HeaderText="Description">
                        <ItemTemplate>
                            <asp:Label ID="lblDescription" runat="server" Text="Label"></asp:Label>
                        </ItemTemplate>
                    </asp:TemplateField>
                    <asp:TemplateField HeaderText="Quantity">
                        <ItemTemplate>
                            <asp:TextBox ID="txtQuantity" runat="server" Width="30px"></asp:TextBox>
                        </ItemTemplate>
                    </asp:TemplateField>
                </Columns>
            </asp:GridView>
        </ContentTemplate>
    </asp:UpdatePanel>
    </form>
</body>
</html>

VB.Net Code Behind
VB.NET:
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"
            drdList.DataBind()
        Next
    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.

Information

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 (Code.zip) 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

Regards
Hav0c
 

Attachments

  • Code.zip
    22.5 KB · Views: 25
Top Bottom