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

Add/Edit with user defined primary key

7 Answers 97 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Phil
Top achievements
Rank 2
Phil asked on 29 Jan 2010, 03:21 AM
Can you give any suggestion on working with add and edit operation with a sample like the NorthWind Customers db?
With identity keys your examples seem to ignore the value and hide it from the user, but do you have a demo like the above.
Phil

7 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 29 Jan 2010, 04:56 AM
Hi,

A suggestion would be to bind a GridBoundColumn  to the primary key field and then set its Visible property to False. In the edit mode you will be able to edit or insert the primary key field which will otherwise not be visble to the user in normal mode.Make sure that you use the EditMode   "EditForms" and not  "Inplace".


Thanks,
Princy
0
Phil
Top achievements
Rank 2
answered on 29 Jan 2010, 01:09 PM
I have a couple of forms that I would like to use InPlace edit-form.  What is the issue with InPlace?  Could it be solved by converting to GridTemplateColumn?
Phil
0
Yavor
Telerik team
answered on 04 Feb 2010, 07:35 AM
Hello Phil,

The approach mentioned previously is still applicable if you are using inline editing as well.
Let me know how this setup falls short in meeting your requirements.

Kind regards,
Yavor
the Telerik team

Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Follow the status of features or bugs in PITS and vote for them to affect their priority.
0
Phil
Top achievements
Rank 2
answered on 10 Feb 2010, 02:25 AM
What is the mentioned issue with InPlace? 
0
Iana Tsolova
Telerik team
answered on 15 Feb 2010, 04:08 PM
Hello Phil,

Could you please specify what is the issue you are facing with the RadGrid InPlace edit mode? Please elaborate a bit on your scenario and if possible share your grid declaration here.

Best wishes,
Iana
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Phil
Top achievements
Rank 2
answered on 28 Apr 2010, 02:28 AM
Example using Northwind customer table:
<Telerik:GridTemplateColumn HeaderText="CustomerID" UniqueName="CustomerIDColumn" AllowFiltering="True" > 
    <ItemTemplate> 
        <asp:Label ID="CustomerIDLabel" runat="server" Text='<%# Eval("CustomerID") %>' /> 
    </ItemTemplate> 
    <EditItemTemplate> 
        <asp:Label ID="CustomerIDLabel" runat="server" Text='<%# Eval("CustomerID") %>' /> 
        <asp:TextBox ID="CustomerIDTextBox" runat="server" Text='<%# Bind("CustomerID") %>' /> 
    </EditItemTemplate> 
</Telerik:GridTemplateColumn> 
 
Code behind:
protected void customersGrid_ItemDataBound(object sender, GridItemEventArgs e) 
    if (e.Item is GridEditableItem && e.Item.IsInEditMode) 
    { 
        // GridTemplateColumn  
        GridEditFormItem _editItem = e.Item as GridEditFormItem; 
        TableCell _cell = _editItem["CustomerIDColumn"]; 
        TextBox _textBox = (_cell.Controls[0].FindControl("CustomerIDTextBox") as TextBox); 
        Label _label = (_cell.Controls[0].FindControl("CustomerIDLabel") as Label); 
        if (e.Item.OwnerTableView.IsItemInserted) 
        { 
            //item is about to be inserted  
            _label.Visible = false
            _textBox.Visible = true
        } 
        else 
        { 
            //item is about to be edited  
            _label.Visible = true
            _textBox.Visible = false
        } 
    } 
 
Phil
0
Iana Tsolova
Telerik team
answered on 03 May 2010, 01:40 PM
Hello Phil,

Try modifying the ItemDataBound event handler as below and see if it makes any difference:

protected void customersGrid_ItemDataBound(object sender, GridItemEventArgs e)
{
    if (e.Item is GridEditableItem && e.Item.IsInEditMode)
    {
        // GridTemplateColumn   
        GridEditableItem _editItem = e.Item as GridEditableItem;
        TableCell _cell = _editItem["CustomerIDColumn"];
        TextBox _textBox = (_cell.Controls[0].FindControl("CustomerIDTextBox") as TextBox);
        Label _label = (_cell.Controls[0].FindControl("CustomerIDLabel") as Label);
        if (e.Item.OwnerTableView.IsItemInserted)
        {
            //item is about to be inserted   
            _label.Visible = false;
            _textBox.Visible = true;
        }
        else
        {
            //item is about to be edited   
            _label.Visible = true;
            _textBox.Visible = false;
        }
    }
}

Let me know how it goes.

Kind regards,
Iana
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
Tags
Grid
Asked by
Phil
Top achievements
Rank 2
Answers by
Princy
Top achievements
Rank 2
Phil
Top achievements
Rank 2
Yavor
Telerik team
Iana Tsolova
Telerik team
Share this question
or