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

Radgrid Using EditFormType="WebUserControl"

1 Answer 298 Views
Grid
This is a migrated thread and some comments may be shown as answers.
David Arnold
Top achievements
Rank 2
David Arnold asked on 30 Jun 2011, 05:23 PM
Hi all,

I am using a webusercontrol for my insert / edit of my radgrid. The insert seems to work fine, except the window doesn't close. After the save, if I click the close X then everything is fine - but it should do that automatically. The other problem is that my edit doesn't work - doesn't pull information in. I'm sure that's because I'm not doing anything to bind it.

So - first question - my .ascx file is using a FormView control and does all of the binding like a normal page would. Is that correct? I really couldn't find a simple example of how to do this.

If 'yes' and I have done that part right - then how do I get my edit to tie to my grid?

Thanks so much. I've included code here:

1. Grid:
<telerik:RadGrid runat="server" ID="gvPatientSearch" DataSourceID="dsPatients" AllowAutomaticInserts="true">
    <ClientSettings>  
        <ClientEvents OnPopUpShowing="PopUpShowing" /> 
    </ClientSettings
    <MasterTableView DataKeyNames="patientID" CommandItemDisplay="Top" Width="100%" EditMode="PopUp">
        <EditFormSettings 
            UserControlName="~/App_Assets/Controls/patientControl.ascx"
            EditFormType="WebUserControl"  
            CaptionDataField="lastName" 
            CaptionFormatString="Edit Patient Record for {0}"
            InsertCaption="New Patient"
            FormStyle-Width="600px"
            
        </EditFormSettings>
        <CommandItemSettings ShowAddNewRecordButton="true" AddNewRecordText="Add New Patient" />
        <Columns>
            ...
            <telerik:GridEditCommandColumn />
        </Columns>
    </MasterTableView>    
</telerik:RadGrid>

2. My user control looks like this:

<%@ Control Language="VB" AutoEventWireup="false" CodeFile="patientControl.ascx.vb" Inherits="App_Assets_Controls_patientControl" %>
    <div align="center">
        <asp:FormView runat="server" ID="fvPatients" DataKeyNames="patientID" DataSourceID="dsPatients" DefaultMode="Insert">
            <EditItemTemplate>
                <table class="searchTable" style="border: 1px solid #2a5690; background-color: #f7f5f0;" cellpadding="3" cellspacing="1" width="99%">
                <tr>
                    <td align="right">Last Name:</td>
                    <td>
                        <telerik:RadTextBox runat="server" ID="txtLastName" Text='<%# Bind("lastName") %>' MaxLength="50" />
                        <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ControlToValidate="txtLastName" CssClass="errorMessage">«</asp:RequiredFieldValidator>
                    </td>
                </tr>
                <tr>
                    <td align="right">First Name:</td>
                    <td>
                        <telerik:RadTextBox runat="server" ID="txtFirstName" Text='<%# Bind("firstName") %>' MaxLength="50" />
                        <asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server" ControlToValidate="txtFirstName" CssClass="errorMessage">«</asp:RequiredFieldValidator>
                    </td>
                </tr>
                <tr>
                    <td align="right">Middle Name:</td>
                    <td>
                        <telerik:RadTextBox runat="server" ID="txtMiddleName" Text='<%# Bind("middleName") %>' MaxLength="50" />
                    </td>
                </tr>
                <tr>
                    <td align="right" valign="top">Sex:</td>
                    <td valign="top">
                        <asp:RadioButtonList runat="server" RepeatDirection="Horizontal" ID="cboSex" SelectedValue='<%# Bind("sex") %>'>
                            <asp:ListItem Text="Male" Value="M" />
                            <asp:ListItem Text="Female" Value="F" />
                        </asp:RadioButtonList>
                        <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="cboSex" CssClass="errorMessage">please choose sex</asp:RequiredFieldValidator>
                    </td>
                </tr>
                <tr>
                    <td align="right">Date of Birth:</td>
                    <td>
                        <telerik:RadDateInput MinDate="01/01/1900" runat="server" ID="dteDateOfBirth" SelectedDate='<%# Bind("dateOfBirth") %>' />
                        <asp:RequiredFieldValidator ID="RequiredFieldValidator4" runat="server" ControlToValidate="dteDateOfBirth" CssClass="errorMessage">«</asp:RequiredFieldValidator>
                    </td>
                </tr>
                <tr>
                    <td align="right">SSN:</td>
                    <td>
                        <telerik:RadMaskedTextBox ID="txtSSN" runat="server" Mask="###-##-####" TextWithLiterals="-" Width="75px" Text='<%# Bind("ssn") %>' />
                        <asp:RequiredFieldValidator ID="RequiredFieldValidator5" runat="server" ControlToValidate="txtSSN" CssClass="errorMessage">«</asp:RequiredFieldValidator>
                    </td>
                </tr>
                <tr>
                    <td align="right">Phone Number:</td>
                    <td>
                        <telerik:RadMaskedTextBox runat="server" ID="txtPhoneNumber" Mask="###-###-####" TextWithLiterals="-" MaxLength="15" Text='<%# Bind("phoneNumber") %>' />
                    </td>
                </tr>
                <tr>
                    <td align="right">Alternate (Cell) Phone Number:</td>
                    <td><telerik:RadMaskedTextBox runat="server" ID="txtPhoneNumber2" Mask="###-###-####" TextWithLiterals="-" MaxLength="15" Text='<%# Bind("phoneNumber2") %>' /></td>
                </tr>
                <tr>
                    <td align="right">Address Line 1:</td>
                    <td><telerik:RadTextBox runat="server" ID="txtAddressLine1" MaxLength="150" Text='<%# Bind("addressLine1") %>' /></td>
                </tr>
                <tr>
                    <td align="right">Address Line 2:</td>
                    <td><telerik:RadTextBox runat="server" ID="txtAddressLine2" MaxLength="150" Text='<%# Bind("addressLine2") %>' /></td>
                </tr>
                <tr>
                    <td align="right">City:</td>
                    <td><telerik:RadTextBox runat="server" ID="txtCity" EmptyMessage="enter city" MaxLength="50" Text='<%# Bind("city") %>' /></td>
                </tr>
                <tr>
                    <td align="right">State:</td>
                    <td><telerik:RadTextBox runat="server" ID="txtState" EmptyMessage="enter state" MaxLength="2" Text='<%# Bind("state") %>' /></td>
                </tr>
                <tr>
                    <td align="right">Zip Code:</td>
                    <td><telerik:RadTextBox runat="server" ID="txtZipCode" EmptyMessage="enter zip code" MaxLength="10" Text='<%# Bind("zipCode") %>' /></td>
                </tr>
                <tr>
                    <td align="right">Email Address:</td>
                    <td><telerik:RadTextBox runat="server" ID="txtEmailAddress" Text='<%# Bind("emailAddress") %>' /></td>
                </tr>
                <tr>
                    <td align="right">Hospital Patient ID:</td>
                    <td><telerik:RadTextBox runat="server" ID="txtHospitalPatientID" Text='<%# Bind("hospitalPatientID") %>' /></td>
                </tr>
                <tr>
                    <td></td>
                    <td><telerik:RadButton CommandName="Insert" runat="server" ID="btnSave" Text="Add Patient" /></td>
                </tr>
                </table>
            </EditItemTemplate>
        </asp:FormView>
    </div>
  
    <asp:SqlDataSource runat="server" ID="dsPatients" 
        SelectCommandType="StoredProcedure" SelectCommand="sp_Patients"
        InsertCommandType="StoredProcedure" InsertCommand="sp_Patients"
        UpdateCommandType="StoredProcedure" UpdateCommand="sp_Patients"
        >
        <SelectParameters>
            <asp:Parameter Name="Action" DefaultValue="SELECT" />
            <asp:QueryStringParameter Name="patientID" QueryStringField="patientID" />
        </SelectParameters>
        <InsertParameters>
            <asp:Parameter Name="Action" DefaultValue="INSERT" />
            <asp:CookieParameter Name="lastUpdatedBy" CookieName="userName" />
        </InsertParameters>
        <UpdateParameters>
            <asp:Parameter Name="Action" DefaultValue="UPDATE" />
            <asp:CookieParameter Name="lastUpdatedBy" CookieName="userName" />
        </UpdateParameters>
    </asp:SqlDataSource>

Thanks for your help!

1 Answer, 1 is accepted

Sort by
0
Marin
Telerik team
answered on 01 Jul 2011, 02:18 PM
Hello David,

 When you use custom user control for the update / insert functionality you should manually handle the update / insert command for the grid and perform there the operation with the database. In this case the AllowAutomaticInserts property should have its default value false. So you should set it to false in order for the window to close automatically. More information on the automatic operations can be found in this help topic.

For the second question you can have a look at this demo showing editing in grid with custom user control. Also this help topic shows how to connect the user control and the grid.

Hope this helps.

Greetings,
Marin
the Telerik team

Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

Tags
Grid
Asked by
David Arnold
Top achievements
Rank 2
Answers by
Marin
Telerik team
Share this question
or