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

Mixed readonly and read-write rows?

4 Answers 178 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Jeff
Top achievements
Rank 1
Jeff asked on 28 Dec 2010, 12:44 AM
I am populating a RadGrid from a DataTable. Each of the DataRows in the DataTable has a "readonly" column with a value of true or false.

The grid currently has a GridEditCommand column, and a GridButtonColumn that triggers the "Delete" command.

What I need is for rows that display records for which "readonly" is true to be read-only.  I need the icon in the GridEditCommand column to be different, and for clicking it to bring up a view-details form, instead of an edit form.  And I need the link in the "Delete" GridButtonColumn to be absent.

It looks like it'd be pretty straightforward to create a table that doesn't allow the user to edit or to delete records, but I need to be able to have some rows editable and some not.

Where should I start?

4 Answers, 1 is accepted

Sort by
0
Accepted
Princy
Top achievements
Rank 2
answered on 28 Dec 2010, 07:24 AM
Hello Jeff,

In order to achieve this, check the value of "readonly" column in ItemDataBound event and make the Delete button visible/invisible based on that value. Similarly based on that value you can change the icon for edit button. And if you want separate form for edit and view details, you can try the following approach. Use FormTemplate for edit and add two Ajax panel (one for edit form and other for viewing details). Initially make the visibility of second panel(for viewing details) as false. And in ItemCommand event check for the Command Name and if it is Edit Command with 'readonly' value as 'true' hide the first panel and show the second one.

ASPX:
<telerik:GridEditCommandColumn ButtonType="ImageButton" UniqueName="EditCommandColumn">
</telerik:GridEditCommandColumn>
<telerik:GridButtonColumn CommandName="Delete" Text="Delete" UniqueName="DeleteButton">
</telerik:GridButtonColumn>

C#:
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
    {
        if (e.Item is GridDataItem)
        {
            GridDataItem item = (GridDataItem)e.Item;
            DataRowView rowview=(DataRowView)item.DataItem;
            string value=rowview["readonly"].ToString();
            if (value=="True")
            {
                LinkButton deletebtn = (LinkButton)item["DeleteButton"].Controls[0];
                deletebtn.Visible = false;
                ImageButton editButton = (ImageButton)item["EditCommandColumn"].Controls[0];
                editButton.ImageUrl = "~/Images/Bitmap1.gif";
               
            }
        }
    }

Thanks,
Princy.
0
Jeff
Top achievements
Rank 1
answered on 28 Dec 2010, 05:15 PM
That's mostly working, except that I can't get the "Edit" tool-tip to change, on a row-by-row basis.

If I set "EditText=" in the markup for the GridEditCommandColumn, that works, but it changes the tool-tip for the icon on every row.

So I'm trying to set the tool-tip in RadGrid_ItemDataBound:

if (e.Item is GridDataItem)
{
    GridDataItem dataItem = e.Item as GridDataItem;
    TableCell editCell = dataItem["EditCommandColumn"];
    editCell.ToolTip = "XXX";
}

The tool-tip on the icon stays "Edit".
0
Jeff
Top achievements
Rank 1
answered on 28 Dec 2010, 06:55 PM
A clarification on the above.

Setting tooltip, on the cell, was actually changing the tooltip on the cell, but it wasn't changing the tooltip on the image.  The blank area around the image had the tooltip I had wanted.

if (e.Item is GridDataItem)
{
    GridDataItem dataItem = e.Item as GridDataItem;
    TableCell editCell = dataItem["EditCommandColumn"];
    ImageButton editButton = editCell.Controls[0] as ImageButton;
    editButton.ImageUrl = "../img/view.gif";
    editButton.ToolTip = "View";
}
0
Pavlina
Telerik team
answered on 03 Jan 2011, 09:31 AM
Hi Jeff,

More information about how to localize the Edit/Update/Cancel buttons text is available here:
Localizing edit command column

Give it a try and let me know if it works as expected.

Regards,
Pavlina
the Telerik team
Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
Tags
Grid
Asked by
Jeff
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Jeff
Top achievements
Rank 1
Pavlina
Telerik team
Share this question
or