ASP.NET

Moderators: None (Apply to moderate this forum)
Number of threads: 1740
Number of posts: 3315

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
GridView with Nested ComboBox Posted by Hav0c1 on 15 Jul 2011 at 10:54 AM
Hello to all readers.
(Seeing it contains ASP.Net code and mainly ASP.Net with VB.Net code behind)

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
<%@ 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
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
AjaxControlToolkit 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
Attachment: Code.zip (23047 Bytes | downloaded 103 times)



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.