Wrox Programmer Forums
|
ASP.NET 1.0 and 1.1 Basics ASP.NET discussion for users new to coding in ASP.NET 1.0 or 1.1. NOT for the older "classic" ASP 3 or the newer ASP.NET 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.0 and 1.1 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 8th, 2005, 06:40 AM
Friend of Wrox
 
Join Date: Apr 2004
Posts: 105
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to RPG SEARCH
Default DDL in DG (binding problem)

Hi there.

I am having difficulty in binding to a ddl in a datagrid when the edit button is clicked. I have tried all sorts of things and i am now pulling my hair out.

Database function:
Function getEditCategories() As System.Data.DataSet

                 Dim ConnectionString As String = ConfigurationSettings.AppSettings("ConnectionStrin g")

                 Dim dbConnection As System.Data.IDbConnection = New System.Data.OleDb.OleDbConnection(connectionString )



                 Dim queryString As String = "SELECT [tblCategories].* FROM [tblCategories]"

                 Dim dbCommand As System.Data.IDbCommand = New System.Data.OleDb.OleDbCommand

                 dbCommand.CommandText = queryString

                 dbCommand.Connection = dbConnection



                 Dim dataAdapter As System.Data.IDbDataAdapter = New System.Data.OleDb.OleDbDataAdapter

                 dataAdapter.SelectCommand = dbCommand

                 Dim dataSet As System.Data.DataSet = New System.Data.DataSet

                 dataAdapter.Fill(dataSet)



                 Return dataSet

                 End Function

The button...
     Sub dgSubCategories_EditCommand(sender As Object, e As DataGridCommandEventArgs)

             dgSubCategories.EditItemIndex = e.Item.Itemindex





             Dim ddl as dropdownlist = CType(e.item.findcontrol("ddlEditCategories"), DropDownList)

             ddl.DataSource() = getEditCategories()

             ddl.DataValueField = "CategoryID"

             ddl.DataTextField = "CategoryName"

             ddl.DataBind()



         End Sub


And finally the grid:

<asp:DataGrid id="dgSubCategories" runat="server" CellPadding="3" AutoGenerateColumns="False" OnUpdateCommand="dgSubCategories_UpdateCommand"

      OnCancelCommand="dgSubCategories_CancelCommand" OnEditCommand="dgSubCategories_EditCommand" DataKeyField="SubCategoryID"

      OnDeleteCommand="dgSubCategories_Delete">

                <EditItemStyle backcolor="#E0E0E0"></EditItemStyle>

                <Columns>

                    <asp:BoundColumn DataField="SubCategoryID" ReadOnly="True" HeaderText="Sub Cat ID">

                        <ItemStyle horizontalalign="Center"></ItemStyle>

                    </asp:BoundColumn>

                    <asp:BoundColumn DataField="SubCategoryName" HeaderText="Sub Category Name">

                        <ItemStyle horizontalalign="Center"></ItemStyle>

                    </asp:BoundColumn>

                    <asp:TemplateColumn HeaderText="Main Category">

                        <ItemTemplate>

                            <%# DataBinder.Eval(Container.DataItem, "CategoryName") %>

                        </ItemTemplate>

                        <EditItemTemplate>

                            <asp:DropDownList runat="server" id="ddlEditCategories" DataValueField="CategoryID" DataTextField="CategoryName" />

                        </EditItemTemplate>

                    </asp:TemplateColumn>

                    <asp:EditCommandColumn ButtonType="LinkButton" UpdateText="Update" CancelText="Cancel" EditText="Edit"></asp:EditCommandColumn>

                    <asp:ButtonColumn Text="Delete" CommandName="Delete"></asp:ButtonColumn>

                </Columns>

            </asp:DataGrid>

Any ideas.. i have tried all sorts!!

cheers

dave

David Jenkins
-------------------------------------------------------------
Do you want to make extra money around your commitments?
Credit cards, bills, loans and a mortgage - all getting you down?
Is your pension going to be enough when you retire?
There is a solution visit http://www.1stmillion.co.uk
or call 01772 489521
__________________
David Jenkins
 
Old March 8th, 2005, 10:55 AM
Friend of Wrox
 
Join Date: Nov 2003
Posts: 1,348
Thanks: 0
Thanked 5 Times in 5 Posts
Default

Where are you initially binding the data grid? In getEditCategories() I see you filling the data set, but not binding the grid.
 
Old March 8th, 2005, 12:50 PM
Friend of Wrox
 
Join Date: Apr 2004
Posts: 105
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to RPG SEARCH
Default

The dg is called subcategories and is bound from here:

 Function getSubCategories() As System.Data.IDataReader
                 Dim connectionString As String = ConfigurationSettings.AppSettings("ConnectionStrin g")
                 Dim dbConnection As System.Data.IDbConnection = New System.Data.OleDb.OleDbConnection(connectionString )

                 Dim queryString As String = "SELECT [tblSubCategory].* FROM [tblSubCategory]"
                 Dim dbCommand As System.Data.IDbCommand = New System.Data.OleDb.OleDbCommand
                 dbCommand.CommandText = queryString
                 dbCommand.Connection = dbConnection

                 dbConnection.Open
                 Dim dataReader As System.Data.IDataReader = dbCommand.ExecuteReader(System.Data.CommandBehavio r.CloseConnection)

                 Return dataReader
                 End Function

and bound here:

in the if not page postback..
         dgSubCategories.DataSource() = getSubCategories()
         dgSubCategories.DataBind()

someone asp.net forum offered this solution...

http://asp.net/Forums/ShowPost.aspx?...&PostID=849180



David Jenkins
-------------------------------------------------------------
Do you want to make extra money around your commitments?
Credit cards, bills, loans and a mortgage - all getting you down?
Is your pension going to be enough when you retire?
There is a solution visit http://www.1stmillion.co.uk
or call 01772 489521





Similar Threads
Thread Thread Starter Forum Replies Last Post
how can selectedvalue of DDL make other DDL visibl hertendreef ASP.NET 2.0 Professional 4 May 20th, 2008 04:38 PM
Gridview problem in Binding ndramkumar ASP.NET 2.0 Professional 1 September 2nd, 2007 11:45 PM
problem with populating ddl in edit of detailsview hertendreef ASP.NET 2.0 Professional 1 August 16th, 2007 12:21 PM
Container Binding problem tany4u Javascript How-To 0 October 3rd, 2006 01:36 AM
Data Binding Problem jbenson001 ASP.NET 1.x and 2.0 Application Design 3 December 18th, 2003 01:03 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.