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

how to trigger a edit command without using the editcommandcolumn or itemcommand column?

3 Answers 108 Views
Grid
This is a migrated thread and some comments may be shown as answers.
xiang
Top achievements
Rank 1
xiang asked on 07 Feb 2014, 07:44 PM
I have a radgrid to dsiplay employee information. I would like to display the name field as a link, and click the name to trigger the edit command. Does anyone know how to do it?

Thanks for your help.

3 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 10 Feb 2014, 05:21 AM
Hi Xiang,

You can use a GridButtonColumn and set its CommandName as Edit and if you want to edit that field you can have it in a BoundColumn with display as false. Please try the below code snippet:

ASPX:
<telerik:GridButtonColumn DataTextField="Name" CommandName="Edit" ButtonType="LinkButton">
</telerik:GridButtonColumn>
<telerik:GridBoundColumn UniqueName="Name" DataField="Name" HeaderText="Name" Display="false">
</telerik:GridBoundColumn>

Thanks,
Princy

0
xiang
Top achievements
Rank 1
answered on 13 Feb 2014, 09:28 PM
I don't want to use the GridButtonColumn either. I want to have the column data bound to the name field and displayed like a link. Click the name will bring up the Edit form or pop-up window.

Thanks,
0
Princy
Top achievements
Rank 2
answered on 14 Feb 2014, 08:14 AM
Hi xiang,

Please try the following code snippet:

ASPX:
<telerik:GridBoundColumn DataField="ShipCity" HeaderText="ShipCity" UniqueName="ShipCity" />

C#:
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
{
    if (e.Item is GridDataItem)
    {
        GridDataItem item = (GridDataItem)e.Item;
        foreach (GridColumn col in RadGrid1.MasterTableView.Columns)
        {
            if (col.UniqueName == "ShipCity")
            {
                LinkButton lnk = new LinkButton();
                lnk.ID = "LinkButton" + col.UniqueName;
                lnk.Text = item[col.UniqueName].Text;
                lnk.CommandName = "Edit";
                item[col.UniqueName].Controls.Add(lnk);
            }
        }
    }
}
protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e)
{
    if (e.Item is GridDataItem)
    {
        GridDataItem item = (GridDataItem)e.Item;
        foreach (GridColumn col in RadGrid1.MasterTableView.Columns)
        {
            if (col.UniqueName == "ShipCity")
            {
                LinkButton lnk = new LinkButton();
                lnk.ID = "LinkButton" + col.UniqueName;
                lnk.Text = item[col.UniqueName].Text;
                lnk.CommandName = "Edit";
                item[col.UniqueName].Controls.Add(lnk);
            }
        }
    }
}

Thanks,
Princy
Tags
Grid
Asked by
xiang
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
xiang
Top achievements
Rank 1
Share this question
or