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

[Solved] RadGrid

1 Answer 102 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Kent
Top achievements
Rank 1
Kent asked on 10 May 2013, 05:41 PM

I would like to turn the ID column of a dynamically created table into an edit button.  Is this possible?  I have seen plenty of documents on creating button columns, but I want to convert a column from text to a button column in the _ColumnCreated or covert each cell in the _PreRender.

Protected Sub RadGrid1_PreRender(ByVal sender As Object, ByVal e As System.EventArgs) Handles QueryRadGrid.PreRender
    Dim intColIndex As Integer
    Dim gridRow As GridDataItem
 
    For Each column As GridColumn In QueryRadGrid.MasterTableView.AutoGeneratedColumns
        If column.UniqueName = "ID" Then
            intColIndex = column.OrderIndex
            For Each gridRow In QueryRadGrid.MasterTableView.Items
                Dim editCol As GridButtonColumn = New GridButtonColumn
                editCol.ButtonType = GridButtonColumnType.LinkButton
                editCol.DataTextField = gridRow.Cells(intColIndex).Text
                ' How do I convert this cell???
                'gridRow.Cells(intColIndex) = ???
            Next
        End If
    Next

Private Sub QueryRadGrid_ColumnCreated(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridColumnCreatedEventArgs) Handles QueryRadGrid.ColumnCreated
    Dim field As String
    Try
        field = e.Column.UniqueName
        If Not field = Nothing AndAlso field <> "" AndAlso field <> "ExpandColumn" Then
            If DataSet.Tables(TableName).Columns(field).ColumnName = "ID" Then
                e.Column.HeaderText = ""
                     DO SOMETHING HERE TO CONVERT COLUMN

1 Answer, 1 is accepted

Sort by
0
Jayesh Goyani
Top achievements
Rank 2
answered on 11 May 2013, 02:02 PM
Hello,

Please try with below code snippet.

protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e)
        {
            if (e.Item is GridDataItem)
            {
                GridDataItem item = e.Item as GridDataItem;
 
                Button link = new Button();
                link.Text = "Button";
                link.CommandName = RadGrid.EditCommandName;
                link.ID = "btn" + item.ItemIndex;
                item["ID"].Controls.Add(link);
            }
             
                 
             
        }
 
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
        {
 
            if (e.Item is GridDataItem)
            {
                GridDataItem item = e.Item as GridDataItem;
 
                Button link = new Button();
                link.Text = "Button";
                link.CommandName = RadGrid.EditCommandName;
                link.ID = "btn" + item.ItemIndex;
                item["ID"].Controls.Add(link);
            }
}


Thanks,
Jayesh Goyani
Tags
Grid
Asked by
Kent
Top achievements
Rank 1
Answers by
Jayesh Goyani
Top achievements
Rank 2
Share this question
or