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

InPlace / In Line Editing

1 Answer 251 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Daniel
Top achievements
Rank 1
Daniel asked on 29 May 2014, 08:11 PM
Hi
I have a very simple requirement that I am pretty sure i have seen demo'ed in the past on the telerik site, but it seems to be gone. I have a grid, and Item templates, as well as EditItemTemplates for each column. One column's edit template is a radcombobox that has to have its datasource set in the code-behind. So, I have a, GridEditCommandColumn.

When I hit "Edit", the grid does not seem to recognize that it is in "Edit"mode. It comes back with the row as it was, uneditable, and the "Edit"button still showing (instead of the expected "Update, Cancel" buttons). Strangely enough, though, there is an edit form below the row that pops down, and it ha s some basic controls for editing, but they are not the edititemtemplate controls, as there are just textboxes, and no radcombobox. In this edit form, there is an update and cancel button. (As you can see in the screenshot, the weird edit form is there, with update and cancel buttons, but the inline row is still in regular mode, and the "edit" button is showing, which implies that the grid is not in edit mode!) I have set EditMode to "INPlace".

I just need simple inline editing - when I click "Edit", the grid should know that the row is in edit mode, and use the edititem template controls inline, as well as show "UPdate and Cancel " buttons. There should be no wierd edit form showing up below my row.

This seems like a super-simple thing to want to do, yet I cannot find a demo of this simple functionality. No demos show how to do in line editing with a radcombobox that has its data source set in ItemDataBound as I am doing.

Any help is appreciated. 

Thanks

Daniel

1 Answer, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 30 May 2014, 05:59 AM
Hi Daniel,

I was not able to replicate such an issue at my end. Please take a look at the sample code which works as expected.

ASPX:
<telerik:RadGrid ID="RadGrid1" runat="server" AutoGenerateColumns="false" AllowPaging="true"
    OnNeedDataSource="RadGrid1_NeedDataSource"  OnItemDataBound="RadGrid1_ItemDataBound">
     <MasterTableView EditMode="InPlace">
        <Columns>
            <telerik:GridEditCommandColumn>
            </telerik:GridEditCommandColumn>
            <telerik:GridBoundColumn DataField="OrderID" HeaderText="OrderID" UniqueName="OrderID" />
            <telerik:GridBoundColumn DataField="ShipName" HeaderText="ShipName" UniqueName="ShipName" />
            <telerik:GridTemplateColumn DataField="ShipCountry">
                <ItemTemplate>
                    <%#Eval("ShipCountry")%>
                </ItemTemplate>
                <EditItemTemplate>
                    <telerik:RadComboBox ID="radcbCountry" runat="server">
                    </telerik:RadComboBox>
                </EditItemTemplate>
            </telerik:GridTemplateColumn>
        </Columns>
    </MasterTableView>
</telerik:RadGrid>

C#:
protected void RadGrid1_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
{
    RadGrid1.DataSource = GetDataTable("SELECT * FROM Orders");
}
 
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
{
    if (e.Item is GridEditableItem && e.Item.IsInEditMode)
    {
        GridEditableItem editItem = (GridEditableItem)e.Item;
        RadComboBox rcbCountry = (RadComboBox)editItem.FindControl("radcbCountry");
        rcbCountry.DataSource = GetDataTable("SELECT distinct ShipCountry FROM Orders");
        rcbCountry.DataTextField = "ShipCountry";
        rcbCountry.DataValueField = "ShipCountry";           
        rcbCountry.DataBind();
        rcbCountry.SelectedValue = DataBinder.Eval(editItem.DataItem, "ShipCountry").ToString();
    }
}
public DataTable GetDataTable(string query)
{
    String ConnString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
    SqlConnection conn = new SqlConnection(ConnString);
    SqlDataAdapter adapter = new SqlDataAdapter();
    adapter.SelectCommand = new SqlCommand(query, conn);
    DataTable myDataTable = new DataTable();
    conn.Open();
    try
    {
        adapter.Fill(myDataTable);
    }
    finally
    {
        conn.Close();
    }
    return myDataTable;
}

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