How to delete a row in Datagrid

  • 14 years ago

    Hi,

    I am trying to delete a row in datagrid. I am primarily working with two classes, UserInfo and UserInfoUtility.

    UserInfo is the class object that stores the data representation of the users table in the database. It exposes properties such as ID,FirstName, Lastname etc. And provides constructors such as UserInfo(), UserInfo(DataRow dr) etc.

    UserInfoUtility provides database access to this table and provides methods such as RetrieveUserByExternal(string id), DeleteUser(UserInfo ui, bool using ExternalID) etc.

    Now, i am using the delete comman in datagrid, My code for the delete command is as follows.

    protected void DataGrid1_DeleteCommand(object source, DataGridCommandEventArgs e)

    {

    string key = DataGrid1.DataKeys[e.Item.ItemIndex].ToString();

    UserInfo ui = UserInfoUtility.RetrieveUserByExternal(key);  //I am getting the following error " An object reference is required for the nonstatic field, method, or property 'Com.Rpi.Erma.Records.UserInfoUtility.DeleteUser(Com.Rpi.Erma.Records.UserInfo, bool)' "

     


    UserInfoUtility.DeleteUser(ui, true);

    DataGrid1.EditItemIndex = -1;

    PerformSearch();

    }

    Can anyone tell me, as to what mistake i am doing and how should i write the code to delete the user from the database using datagrid. I am fairly new to ASP and C#. Kindly help me. Its very urgent.

    Thanks

    Zaid Papa

  • 14 years ago
  • 14 years ago

    I am using classes to view or store the data, the article you mentioned is not much of a use for me. I am basically using dll files.

    Zaid Papa

  • 14 years ago
  • 14 years ago

    Hi,

    I am still getting the same error, " An object reference is required for the non static field......"

    Thanks

    Zaid Papa

  • 13 years ago

    Hi,

    Sorry for the late reply. The error was in the class file UserInfoUtility that i was working with. The DeleteUser() method was in void, when it was supposed to be in static.

    Thanks

    Zaid Papa

Post a reply

Enter your message below

Sign in or Join us (it's free).

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“The difference between theory and practice is smaller in theory than in practice.”