Wrox Programmer Forums
|
ASP.NET 2.0 Professional If you are an experienced ASP.NET programmer, this is the forum for your 2.0 questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Professional 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 November 27th, 2006, 03:45 PM
Authorized User
 
Join Date: Dec 2005
Posts: 21
Thanks: 0
Thanked 0 Times in 0 Posts
Default Gridview.SelectedRow problem

Hi everyone,

I am trying to use the update function on gridview.
The SelectedRow function should return the current row to be
updated, however, I get "Object reference not set to an instance of an object" error. I have checked the variable names and they are correct. could please someone help me!!!

Code:
protected void gviewAccountSub_RowUpdating(object sender, GridViewUpdateEventArgs e) {
        try {
            GridViewRow row = gviewAccountSub.SelectedRow;
            row.RowState = DataControlRowState.Edit;

            DropDownList ddlCurrency = (DropDownList)row.FindControl("ddlvAccountSub_gviewCurrencyEdit");
            DropDownList ddlAccount = (DropDownList)row.FindControl("ddlvAccountSub_gviewAccountEdit");

            e.NewValues["Currency"] = ddlCurrency.SelectedValue;
            e.NewValues["Account"] = ddlAccount.SelectedValue;
        }
 
Old November 28th, 2006, 11:54 PM
Friend of Wrox
 
Join Date: Feb 2006
Posts: 116
Thanks: 0
Thanked 0 Times in 0 Posts
Default

You'd think that would work...

Instead of assuming the selected row is the same as the row generating the event, I think it would be a better idea to cast the sender object (the first argument to this event handler) as GridViewRow and make that your row to work with.

I'm also not sure you can assume those are the names of those two drop downs you are trying to find in the row. That, if I remember correctly doesn't work. ASP.NET names the ddl in each row something different because each row has to have a set of controls with unique ID's right?

Step through the code and find out exactly which statement throws the exception!

Neil Timmerman
Programmer
Veris Consulting
 
Old November 29th, 2006, 12:23 PM
Authorized User
 
Join Date: Sep 2006
Posts: 66
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi ,
use e.SelectedRow;
instead of
GridViewRow row = gviewAccountSub.SelectedRow;


 
Old November 30th, 2006, 01:01 PM
Authorized User
 
Join Date: Dec 2005
Posts: 21
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thank you for your reply!! I managed to get it working by
using the sender and works fine.
GridViewRow row = ((GridView)sender).Rows[e.RowIndex];
I can see now that e.SelectedRow works as well...






Similar Threads
Thread Thread Starter Forum Replies Last Post
Gridview problem in Binding ndramkumar ASP.NET 2.0 Professional 1 September 2nd, 2007 11:45 PM
problem in gridview jaber.moh ASP.NET 2.0 Basics 1 March 19th, 2007 02:47 AM
GridView edit problem mike72 ASP.NET 2.0 Basics 8 January 3rd, 2007 07:59 PM
Problem in GridView mohsin_khan BOOK: Wrox's ASP.NET 2.0 Visual Web Developer 2005 Express Edition Starter ISBN: 978-0-7645-8807-5 1 November 15th, 2006 03:07 PM





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