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

How do i pass primary key to grid to save function of inline popup ?.

1 Answer 87 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Philip
Top achievements
Rank 1
Philip asked on 07 Apr 2016, 11:46 AM

I am trying to figure out how to achevie the following I am using the edit pop to allow user to edit multple note records my problem I am having is that I cant seem to figure out how to get the id passed to my save command on the popup dialog.

01.<telerik:RadGrid ID="rgNotes" runat="server" GroupPanelPosition="Top" OnItemCommand="rgNotes_ItemCommand">
02.                            <GroupingSettings CollapseAllTooltip="Collapse all groups"></GroupingSettings>
03.                            <MasterTableView NoDetailRecordsText="No notes for this Appointment" AutoGenerateColumns="False" CommandItemDisplay="Top" CommandItemSettings-AddNewRecordText="Add Notes" AllowAutomaticInserts="true" EditMode="PopUp">
04.                                <Columns>
05.                                    <telerik:GridEditCommandColumn UniqueName="EditCommandColumn">
06.                                    </telerik:GridEditCommandColumn>
07.                                     <telerik:GridBoundColumn DataField="notes_id" FilterControlAltText="Filter notes_id column" HeaderText="notes_id" ReadOnly="True" SortExpression="notes_id" Visible="false" UniqueName="notes_id">
08.                                    </telerik:GridBoundColumn>
09.                                    <telerik:GridBoundColumn DataField="Subject" FilterControlAltText="Filter Subject column" HeaderText="Subject" ReadOnly="True" SortExpression="Subject" UniqueName="Subject">
10.                                    </telerik:GridBoundColumn>
11.                                </Columns>
12. 
13.                                <EditFormSettings EditFormType="Template" InsertCaption="Add new Note" CaptionFormatString="Please enter or update note">
14.                                    <FormTemplate>
15. 
16.                                        <telerik:RadTextBox ID="txtNotesId" Width="200px" runat="server"></telerik:RadTextBox>
17. 
18.                                        Subject
19.                                        <p>
20.                                            <telerik:RadTextBox ID="txtSubjectNotes" Width="200px" runat="server"></telerik:RadTextBox>
21.                                        </p>
22.                                        <p>
23.                                            Notes<br />
24.                                            <telerik:RadTextBox ID="RadTextBox1" TextMode="MultiLine" Rows="10" Columns="10" Width="200px" runat="server"></telerik:RadTextBox>
25.                                        </p>
26. 
27.                                        <telerik:RadButton ID="rdSaveNotes" OnClick="rdSaveNotes_Click" Skin="Bootstrap" BackColor="#512479" ForeColor="White" runat="server" Text="Save Notes"></telerik:RadButton>
28.                                        <telerik:RadButton ID="rdCancel" OnClick="rdCancel_Click1" CommandName="Cancel" Skin="Bootstrap" BackColor="#512479" ForeColor="White" runat="server" Text="Cancel"></telerik:RadButton>
29.                                    </FormTemplate>
30.                                </EditFormSettings>
31.                            </MasterTableView>
32.                            <ClientSettings>
33.                                <ClientEvents OnPopUpShowing="PopUpShowing" />
34.                                <Selecting AllowRowSelect="true" />
35.                            </ClientSettings>
36.                        </telerik:RadGrid>
37.                    </telerik:RadAjaxPanel>

Obv I need a way of passing the value to my save event but I cant seem to think how at present I no in the grids normal way of doing it you can dothis in the item command.

 

01.protected void rdSaveNotes_Click(object sender, EventArgs e)
02.{
03.    try
04.    {
05.        int id = Convert.ToInt32(Request.QueryString["id"]);
06.        tblApertureNetNote _note = new tblApertureNetNote();
07. 
08.        // _note = _dal.GetNotesById(id);
09. 
10.        _note.appointment_id = id;
11. 
12.        _note.isActive = true;
13.        _note.isDeleted = false;
14.        _note.subject = txtSubject.Text;
15.        if (_note.EntityState == System.Data.EntityState.Detached)
16.            _dal.Addnotes(_note);
17. 
18.        rgNotes.DataBind();
19.    }
20.    catch (Exception ex)
21.    {
22.        logger.Error("Error in rdSaveNotes_Click function calandar edit.aspx" + ex.ToString());
23.    }
24.}

 

And this is how I would normally pass the primary key but here I do not no how to ?.

 

1.protected void rgNotes_ItemCommand(object sender, Telerik.Web.UI.GridCommandEventArgs e)
2.      {
3.          GridDataItem item = e.Item as GridDataItem;
4.          Guid id = new Guid(item.GetDataKeyValue("notes_id").ToString());
5.      }

1 Answer, 1 is accepted

Sort by
0
Eyup
Telerik team
answered on 12 Apr 2016, 10:36 AM
Hello Philip,

You should add the field name in the following collection:
<MasterTableView ... DataKeyNames="notes_id">

You can also check this live sample:
http://demos.telerik.com/aspnet-ajax/grid/examples/data-editing/form-template-update/defaultcs.aspx

I hope this will prove helpful.

Regards,
Eyup
Telerik
Do you need help with upgrading your ASP.NET AJAX, WPF or WinForms projects? Check the Telerik API Analyzer and share your thoughts.
Tags
Grid
Asked by
Philip
Top achievements
Rank 1
Answers by
Eyup
Telerik team
Share this question
or