Radgrid Using EditFormType="WebUserControl"

2 posts, 0 answers
  1. David Arnold
    David Arnold avatar
    13 posts
    Member since:
    Jul 2009

    Posted 30 Jun 2011 Link to this post

    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">
            <ClientEvents OnPopUpShowing="PopUpShowing" /> 
        <MasterTableView DataKeyNames="patientID" CommandItemDisplay="Top" Width="100%" EditMode="PopUp">
                CaptionFormatString="Edit Patient Record for {0}"
                InsertCaption="New Patient"
            <CommandItemSettings ShowAddNewRecordButton="true" AddNewRecordText="Add New Patient" />
                <telerik:GridEditCommandColumn />

    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">
                    <table class="searchTable" style="border: 1px solid #2a5690; background-color: #f7f5f0;" cellpadding="3" cellspacing="1" width="99%">
                        <td align="right">Last Name:</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 align="right">First Name:</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 align="right">Middle Name:</td>
                            <telerik:RadTextBox runat="server" ID="txtMiddleName" Text='<%# Bind("middleName") %>' MaxLength="50" />
                        <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:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="cboSex" CssClass="errorMessage">please choose sex</asp:RequiredFieldValidator>
                        <td align="right">Date of Birth:</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 align="right">SSN:</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 align="right">Phone Number:</td>
                            <telerik:RadMaskedTextBox runat="server" ID="txtPhoneNumber" Mask="###-###-####" TextWithLiterals="-" MaxLength="15" Text='<%# Bind("phoneNumber") %>' />
                        <td align="right">Alternate (Cell) Phone Number:</td>
                        <td><telerik:RadMaskedTextBox runat="server" ID="txtPhoneNumber2" Mask="###-###-####" TextWithLiterals="-" MaxLength="15" Text='<%# Bind("phoneNumber2") %>' /></td>
                        <td align="right">Address Line 1:</td>
                        <td><telerik:RadTextBox runat="server" ID="txtAddressLine1" MaxLength="150" Text='<%# Bind("addressLine1") %>' /></td>
                        <td align="right">Address Line 2:</td>
                        <td><telerik:RadTextBox runat="server" ID="txtAddressLine2" MaxLength="150" Text='<%# Bind("addressLine2") %>' /></td>
                        <td align="right">City:</td>
                        <td><telerik:RadTextBox runat="server" ID="txtCity" EmptyMessage="enter city" MaxLength="50" Text='<%# Bind("city") %>' /></td>
                        <td align="right">State:</td>
                        <td><telerik:RadTextBox runat="server" ID="txtState" EmptyMessage="enter state" MaxLength="2" Text='<%# Bind("state") %>' /></td>
                        <td align="right">Zip Code:</td>
                        <td><telerik:RadTextBox runat="server" ID="txtZipCode" EmptyMessage="enter zip code" MaxLength="10" Text='<%# Bind("zipCode") %>' /></td>
                        <td align="right">Email Address:</td>
                        <td><telerik:RadTextBox runat="server" ID="txtEmailAddress" Text='<%# Bind("emailAddress") %>' /></td>
                        <td align="right">Hospital Patient ID:</td>
                        <td><telerik:RadTextBox runat="server" ID="txtHospitalPatientID" Text='<%# Bind("hospitalPatientID") %>' /></td>
                        <td><telerik:RadButton CommandName="Insert" runat="server" ID="btnSave" Text="Add Patient" /></td>
        <asp:SqlDataSource runat="server" ID="dsPatients" 
            SelectCommandType="StoredProcedure" SelectCommand="sp_Patients"
            InsertCommandType="StoredProcedure" InsertCommand="sp_Patients"
            UpdateCommandType="StoredProcedure" UpdateCommand="sp_Patients"
                <asp:Parameter Name="Action" DefaultValue="SELECT" />
                <asp:QueryStringParameter Name="patientID" QueryStringField="patientID" />
                <asp:Parameter Name="Action" DefaultValue="INSERT" />
                <asp:CookieParameter Name="lastUpdatedBy" CookieName="userName" />
                <asp:Parameter Name="Action" DefaultValue="UPDATE" />
                <asp:CookieParameter Name="lastUpdatedBy" CookieName="userName" />

    Thanks for your help!
  2. Marin
    Marin avatar
    1038 posts

    Posted 01 Jul 2011 Link to this post

    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.

    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.

  3. DevCraft R3 2016 release webinar banner
Back to Top