Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > C# and C > C# 1.0 > C#
Password Reminder
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
C# Programming questions specific to the Microsoft C# language. See also the forum Beginning Visual C# to discuss that specific Wrox book and code.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C# section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old December 12th, 2003, 08:48 PM
Friend of Wrox
Join Date: Jun 2003
Location: Harrisburg, PA, USA.
Posts: 1,998
Thanks: 0
Thanked 3 Times in 3 Posts
Default Data Grid Editing in C#


I'm trying to access the values from a data grid. I have a data grid control, and have use the OnItemCommand Event as follows:
private void dgrResults_ItemCommand(object sender, DataGridCommandEventArgs e) {
        DataGrid objGrid = (DataGrid) sender;

        switch (e.CommandName.ToLower()) {
            case "cancel":
                objGrid.EditItemIndex = -1;

            case "delete":
                //Where error occurs, says "cannot convert string to int")
                TextTable.Rows.Remove(TextTable.Rows.Find((int) e.Item.Cells[0].Text));

            case "edit":
                objGrid.EditItemIndex = e.Item.ItemIndex;

            case "update":
                TextBox objText = (TextBox) e.Item.Cells[1].Controls[0];
                DropDownList objStyle = (DropDownList) e.Item.Cells[2].Controls[0];

                //No error here, but it wasn't working above so I assume it won't work here also
                UpdateData((int) e.Item.Cells[0].Text, objText.Text, objStyle.SelectedValue);


        objGrid = null;
Where I get the ID (e.Item.Cells[0].Text) which is a bound column, it says cannot convert string to int (see comments in code which specify the errors). I'm guessing it's because it's returning an empty string, and it can't convert it to a number... but I don't know. Any ideas?


Brian Mains
Reply With Quote
  #2 (permalink)  
Old December 16th, 2004, 04:23 AM
Registered User
Join Date: Dec 2004
Location: , , .
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts

You cannot explicitly case a string into an integer. Trying using int.Parse("your string here").

Reply With Quote

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Data Binding - Editing GridView Row Data desk_star BOOK: Professional ASP.NET 2.0 and Special Edition; ISBN: 978-0-7645-7610-2; ISBN: 978-0-470-04178-9 7 December 30th, 2007 11:07 AM
grid view row editing event fired after postback sasidhar79 ASP.NET 2.0 Professional 0 January 30th, 2007 08:17 PM
Editing Data in a DataView thenextbillgates ASP.NET 1.0 and 1.1 Basics 3 April 10th, 2006 09:40 PM
Editing Grid with Checkboxes busher ASP.NET 1.0 and 1.1 Basics 4 April 28th, 2005 04:45 AM
Data Grid editing of class bmains Pro VB.NET 2002/2003 3 October 22nd, 2003 12:38 PM

All times are GMT -4. The time now is 12:28 PM.

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