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

[Solved] GridEditCommandColumn not working.

3 Answers 489 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Siva
Top achievements
Rank 1
Siva asked on 14 Mar 2013, 07:20 AM

Hi ... 
  I have a grid , while pressing the edit button only two columns ,one is a Dropdown & another one is texteditor must be in edit mode.I used in-Line edit mode & i used a code to check remaining columns as ReadOnly. wat my prob is when i press the edit button the grid disappears. Please help me with a solution..
MY code is
Aspx:
<telerik:RadGrid ID="RadGrid2" runat="server" 
         AllowPaging="True" AllowSorting="True" AutoGenerateColumns="False" 
         CellSpacing="0" GridLines="None"  AllowAutomaticInserts="True" PageSize="10" AllowAutomaticUpdates="True">
      
<HeaderContextMenu CssClass="GridContextMenu GridContextMenu_Default"></HeaderContextMenu>

      <PagerStyle EnableSEOPaging="True" AlwaysVisible="true" > </PagerStyle>

<MasterTableView EditMode="InPlace" >
<CommandItemSettings ExportToPdfText="Export to PDF"></CommandItemSettings>

<RowIndicatorColumn FilterControlAltText="Filter RowIndicator column">
</RowIndicatorColumn>

<ExpandCollapseColumn FilterControlAltText="Filter ExpandColumn column">
</ExpandCollapseColumn>

    <Columns>
       
        <telerik:GridBoundColumn DataField="ID "
            FilterControlAltText="Filter Record Id column" HeaderText="Record Id"
            SortExpression="ID asc" UniqueName="Record Id">
        </telerik:GridBoundColumn>
        .
 .
 .
 .
 .
        <telerik:GridBoundColumn DataField="Gift"
            FilterControlAltText="Filter Disposition Option column"
            HeaderText="Disposition Option" ReadOnly="True"
            SortExpression="Gift_dispose asc" UniqueName="Disposition Option">
        </telerik:GridBoundColumn>
     
 <telerik:GridDropDownColumn DataField="status"
                    HeaderText="Disposition Status"
                    UniqueName="Disposition Status" ColumnEditorID="GridDropDownColumnEditor">
                </telerik:GridDropDownColumn>

      
         <telerik:GridBoundColumn DataField="Notes" HeaderText="Notes" SortExpression="Notes"
                    UniqueName="Notes" ColumnEditorID="GridTextBoxColumnEditor">
                    </telerik:GridBoundColumn>

      
      
        <telerik:GridEditCommandColumn ButtonType="PushButton" UpdateText="Update" CancelText="Cancel" EditText="Edit"
            FilterControlAltText="Filter EditCommandColumn column">
            
        </telerik:GridEditCommandColumn>        
    </Columns>

<EditFormSettings>
<EditColumn FilterControlAltText="Filter EditCommandColumn column"></EditColumn>
 <EditColumn ButtonType="PushButton"  UpdateText="Update"
                    UniqueName="EditCommandColumn1" CancelText="Cancel edit">
                </EditColumn>
</EditFormSettings>
</MasterTableView>

      <ClientSettings>
          <Selecting AllowRowSelect="True" />
      </ClientSettings>

<FilterMenu EnableImageSprites="False"></FilterMenu>  
     
            </telerik:RadGrid>
             <telerik:GridTextBoxColumnEditor ID="GridTextBoxColumnEditor1" runat="server" TextBoxStyle-Width="200px" TextBoxStyle-Height="500px">
    </telerik:GridTextBoxColumnEditor>

Aspx.cs:

 

 protected void RadGrid2_ItemCommand(object source, GridCommandEventArgs e)
    {

        if (e.CommandName == "Edit")
        {

           
            (RadGrid2.MasterTableView.GetColumn("Id") as GridBoundColumn).ReadOnly = true;
            (RadGrid2.MasterTableView.GetColumn("Date reported") as GridBoundColumn).ReadOnly = true
  .
  .
  .
  RadGrid2.MasterTableView.Rebind();
  }

wat i am missing..? Also i need to add the dropdown list values in GridDropdown column, how to do it   

3 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 14 Mar 2013, 07:44 AM
Hi,

I suppose you are using simple data binding to bind the grid. In order to implement advanced features in RadGrid like editing, paging etc.. make sure that you are using advanced data binding using its NeedDataSource event. Check the following help documentation for more.
Advanced Data-binding (using NeedDataSource event)

Thanks,
Shinu
0
Siva
Top achievements
Rank 1
answered on 14 Mar 2013, 08:47 AM
hi shinu , Am not using default datasource, the data is fetched from the table dynamically based on the search criteria , how can i use advance datasource in it.. (i.e) On button click based on the search parameters passing i have to load the grid dynamically ...  help me with a eg code..  thnx in advance..
0
Radoslav
Telerik team
answered on 19 Mar 2013, 08:12 AM
Hi Siva,

To achieve the desired functionality you can try using the following approach:

Attach NeedDataSource event to the RadGrid:
protected void RadGrid1_NeedDataSource(object source, Telerik.Web.UI.GridNeedDataSourceEventArgs e)
{
   RadGrid1.DataSource = GridDataSource;
}
Where GridDataSource is a collection of items to which the RadGrid is bound and it is kept into the Session:  
public List<DataSourceType> GridDataSource
{
     get
     {
         if (Session["GridDataSource"] == null)
         {
             Session["GridDataSource"] = new List<DataSourceType>();
         }
 
         return Session["GridDataSource"] as List<DataSourceType>;
     }
     set
     {
         Session["GridDataSource"] = value;
     }
 }
Here the DataSourceType is the type of the elements fetched from your table. The List<DataSourceType> can be replaced also with DataTable depending on your scenario.
Then on button click you need to assign data to the GridDataSource property and call RadGrid1.Rebind() method:
void button1_Click(object sender, EventArgs e)
{
     GridDataSource = something;
     RadGrid1.Rebind();
}

I hope this helps.

Kind regards,
Radoslav
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
Tags
Grid
Asked by
Siva
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Siva
Top achievements
Rank 1
Radoslav
Telerik team
Share this question
or