Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 1.0 and 1.1 > ASP.NET 1.1
|
ASP.NET 1.1 As of 10/6/2005, this forum is locked as part of the reorganization described here: http://p2p.wrox.com/topic.asp?TOPIC_ID=35394. No posts have been deleted. Open ongoing discussions from the last week have been moved to either ASP.NET 1.0 and 1.1 Beginners http://p2p.wrox.com/asp-net-1-0-1-1-basics-60/ or ASP.NET 1.0 and 1.1 Professional. http://p2p.wrox.com/forum.asp?FORUM_ID=50. See my sticky post inside for more.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.1 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 January 29th, 2005, 02:00 PM
Friend of Wrox
 
Join Date: Oct 2003
Posts: 218
Thanks: 0
Thanked 0 Times in 0 Posts
Default Setting Selection in Datagrid Edit

I have a datagrid cell that renders as a label when loaded, but in edit mode becomes a drop down list. I want to set the selection on the dropdown list.

I am using the OnEditCommand function to try this. Here's my code:
Code:
Sub dgImpact_Edit(ByVal sender As Object, ByVal e As DataGridCommandEventArgs)
    Dim FundingSource As String = CType(e.Item.FindControl("lblFundingSource"), Label).Text

        GetFundingSources()
        dgImpact.EditItemIndex = e.Item.ItemIndex
        BindImpactGrid()

        Dim ddlFundingSource As DropDownList = CType(e.Item.FindControl("ddlFundingSource"), DropDownList)
        ddlFundingSource.SelectedValue = FundingSource
End Sub
This gives me the dreaded "Object reference not set to an instance of an object" error.

What am I missing? Thanks in advance for your comments.


- - - - - - - - - - - - - - - - - - - - - - -
In God we trust, everything else we test.
 
Old January 30th, 2005, 11:09 AM
Friend of Wrox
 
Join Date: Jul 2004
Posts: 623
Thanks: 0
Thanked 1 Time in 1 Post
Default

do all of them in Update_Command event instead,you need just two lines in Edit_Command,
Code:
dgImpact.EditItemIndex = e.Item.ItemIndex;
BindGrid();
then in Update_Command find your DropDownList and retrieve its properties.

_____________________________
Mehdi.
software engineering student.
Looking for a good job for summer 2005.
 
Old January 31st, 2005, 09:38 AM
Friend of Wrox
 
Join Date: Oct 2003
Posts: 218
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Mehdi-

Thank you for your input. I decided to go the ItemDatabound event route. I found a solution when I was digging around MSDN here: http://msdn.microsoft.com/library/de...verControl.asp

Look under the section "Displaying a Drop-Down List in Edit Mode"

- - - - - - - - - - - - - - - - - - - - - - -
In God we trust, everything else we test.
 
Old January 31st, 2005, 11:44 AM
Friend of Wrox
 
Join Date: Jul 2004
Posts: 623
Thanks: 0
Thanked 1 Time in 1 Post
Default

Quote:
quote:Originally posted by Colonel Angus
 ...I decided to go the ItemDatabound event route.
well,you should have made that decision,for initial population and resetting the properties of the DropDownList,ItemDatabound is used, after that in another event(like Update_Command) you get
the new state of the DropDownList has been made by the user(or everything else).

_____________________________
Mehdi.
software engineering student.
Looking for a good job for summer 2005.





Similar Threads
Thread Thread Starter Forum Replies Last Post
selection of all checkboxes inside the datagrid yes_no ASP.NET 1.0 and 1.1 Professional 4 April 15th, 2008 07:31 AM
Selection in DataGrid Ardvisoor ASP.NET 2.0 Professional 3 June 14th, 2006 09:23 AM
cannot detect selection of checkbox datagrid edit swati_joshi ASP.NET 1.0 and 1.1 Basics 0 April 21st, 2006 08:23 AM
cannot detect selection of checkbox datagrid edit swati_joshi ASP.NET 1.0 and 1.1 Professional 0 April 21st, 2006 08:21 AM
selection index changed in datagrid lily611 General .NET 1 July 21st, 2004 07:56 AM





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