This is a migrated thread and some comments may be shown as answers.

[Solved] Row Edit problem

6 Answers 154 Views
Grid
This is a migrated thread and some comments may be shown as answers.
john
Top achievements
Rank 1
john asked on 05 Feb 2009, 07:54 PM
Hi,

Is there a way to disable row edition in the grid.?On click on edit button, I want the data from the row to be displayed in the server controls on the form for edition.For that I first of all need to disable edition in grid.

6 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 06 Feb 2009, 04:45 AM
Hi John,

I am not sure what exactly is your requirement. For preventing editing of a particular GridColumn you can set the Column's ReadOnly property to true.
  
You can try the following code snippet to prevent editing of entire Grid rows.

protected void RadGrid1_ItemCommand(object source, GridCommandEventArgs e) 
    { 
        if (e.CommandName == "Edit"
        { 
            e.Canceled = true
        } 
    } 


Shinu
0
john
Top achievements
Rank 1
answered on 06 Feb 2009, 07:24 AM
Hi shinu,

Thanks for your reply.Actually I want to get the contents of the row every time edit button is clicked and display it in the server controls that were used to insert the information.The user will then edit the row data there.My employer wants it to work that way.So is there a way for me to access the contents of a row that has its edit button clicked?.
0
Accepted
Daniel
Telerik team
answered on 06 Feb 2009, 08:04 AM
Hello John,

You can access the underlying GridDataItem using the following approach:
protected void RadGrid1_ItemCommand(object source, GridCommandEventArgs e) 
    if(e.CommandName == "Edit"
    { 
        Hashtable values = new Hashtable(); 
        (e.Item as GridDataItem).ExtractValues(values); 
        string yourValue = values["yourValue"].ToString(); 
    } 

Best regards,
Daniel
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Accepted
Princy
Top achievements
Rank 2
answered on 06 Feb 2009, 08:10 AM
Hi John,

If you do not want to edit the row on clicking the button and just get the row data, you may consider using a GridButtonColumn with a CommandName set instead of GridEditCommandColumn. In the ItemCommand event you can check for the CommandName and access the row data.

ASPX:

<
telerik:GridButtonColumn ButtonType="linkbutton" Text="MyCommand"  HeaderText="MyCommandCol"  CommandName="MyCommand"  ></telerik:GridButtonColumn>
 

CS:
  protected void RadGrid1_ItemCommand(object source, GridCommandEventArgs e) 
    { 
        if (e.CommandName == "MyCommand"
        { 
            GridDataItem item = (GridDataItem)e.Item; 
            string strName = item["ProductName"].Text; 
            string strID = item["SupplierID"].Text; 
        } 
   } 


Thanks
Princy.
0
john
Top achievements
Rank 1
answered on 06 Feb 2009, 09:09 AM
thanks for the help guys, my problem has been solved.
0
Jack Jim
Top achievements
Rank 1
answered on 01 Dec 2009, 07:00 AM
Hi Shinu,
thanks a lot...your code worked for my requirement.
Thanks

Tags
Grid
Asked by
john
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
john
Top achievements
Rank 1
Daniel
Telerik team
Princy
Top achievements
Rank 2
Jack Jim
Top achievements
Rank 1
Share this question
or