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

RadGrid with UserControl EditTemplate

1 Answer 130 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Justin
Top achievements
Rank 1
Justin asked on 12 Sep 2011, 10:45 PM
I have a RadGrid that uses a WebUserControl for the EditTemplate. I am trying to make it so when I am editing the records for the Grid in the WebUserControl and I submit the changes it updates the usercontrol and refreshes it with the new data, without closing the Grid. Is this possible?

This is my Grid:
<telerik:radgrid id="grdLeadList" runat="server" autogeneratecolumns="false" allowpaging="True"
    allowsorting="True" pagesize="5" allowautomaticupdates="true" gridlines="None"
    allowmultirowselection="true" onitemcommand="grdLeadList_ItemCommand" OnItemDataBound="grdLeadList_ItemDataBound" OnEditCommand="grdLeadList_EditCommand" OnNeedDataSource="grdLeadList_NeedDataSource" DataKeyNames="opportunityid" style="float: left; width: 965px;">
<ExportSettings HideStructureColumns="true" ExportOnlyData="true" IgnorePaging="true">
    <Excel Format="ExcelML" />
    <Csv ColumnDelimiter="Comma" RowDelimiter="NewLine" />
    <Pdf />
</ExportSettings>
<PagerStyle Mode="NextPrevNumericAndAdvanced" />
<MasterTableView Width="100%" TableLayout="Auto" DataKeyNames="opportunityid">
    <CommandItemSettings ShowExportToExcelButton="false" ShowExportToCsvButton="false" ShowExportToPdfButton="false" ShowAddNewRecordButton="false" />
    <Columns>
        <telerik:GridTemplateColumn UniqueName="CkhSelect" HeaderText="Select">
          <HeaderTemplate>
            <asp:CheckBox ID="chkSelectAll" runat="server" OnCheckedChanged="ToggleSelectedState" AutoPostBack="True"  />
          </HeaderTemplate>           
          <ItemTemplate>
            <asp:CheckBox ID="chkbxselect" OnCheckedChanged="ToggleRowSelection" AutoPostBack="True" runat="server" />
          </ItemTemplate>
        </telerik:GridTemplateColumn>
        <telerik:GridEditCommandColumn ButtonType="LinkButton" UpdateText="Update" CancelText="Cancel" EditText="Edit" UniqueName="ClientSelectEdit" />
        <telerik:GridBoundColumn DataField="OpportunityId" UniqueName="OpportunityId" Visible="false" />
        <telerik:GridBoundColumn DataField="CustomerId" HeaderText="Company Name" SortExpression="CustomerId" UniqueName="CompanyName" />
        <telerik:GridBoundColumn DataField="Priority" HeaderText="Priority" SortExpression="Priority" UniqueName="Priority" />
        <telerik:GridBoundColumn DataField="Eval" HeaderText="Eval" SortExpression="Eval" UniqueName="Eval" />
        <telerik:GridBoundColumn DataField="ContactName" HeaderText="Contact Name" SortExpression="ContactName" UniqueName="ContactName" />
        <telerik:GridBoundColumn DataField="Source" HeaderText="Source" SortExpression="Source" UniqueName="Source" />
        <telerik:GridBoundColumn DataField="State" HeaderText="State" SortExpression="State" UniqueName="State" />
        <telerik:GridNumericColumn DataField="Zip" HeaderText="Zip" SortExpression="Zip" UniqueName="Zip" />
        <telerik:GridBoundColumn DataField="ContactStreetAddress" UniqueName="ContactStreetAddress" Visible="false" />
        <telerik:GridBoundColumn DataField="ContactCity" UniqueName="ContactCity" Visible="false" />
        <telerik:GridBoundColumn DataField="ContactState" UniqueName="ContactState" Visible="false" />
        <telerik:GridBoundColumn DataField="ContactZip" UniqueName="ContactZip" Visible="false" />
        <telerik:GridBoundColumn DataField="ContactPhone" UniqueName="ContactPhone" Visible="false" />
        <telerik:GridBoundColumn DataField="ContactMobilePhone" UniqueName="ContactMobilePhone" Visible="false" />
        <telerik:GridBoundColumn DataField="ContactEmail" UniqueName="ContactEmail" Visible="false" />
        <telerik:GridBoundColumn DataField="Notes" UniqueName="Notes" Visible="false" />
        <telerik:GridBoundColumn DataField="EstimatedCloseDate" UniqueName="EstimatedCloseDate" Visible="false" />
        <telerik:GridBoundColumn DataField="MaturityValue" UniqueName="MaturityValue" Visible="false" />
        <telerik:GridDateTimeColumn DataField="CreatedOn" DataFormatString="{0:MM/dd/yy}" HeaderText="Creation Date" SortExpression="CreatedOn" UniqueName="CreationDate" />
        <telerik:GridBoundColumn DataField="DistributorStatus" UniqueName="DistributorStatus" Visible="false" />        
    </Columns>
    <EditFormSettings UserControlName="~/LeadShareEditPanel.ascx" EditFormType="WebUserControl">
        <EditColumn UniqueName="EditCommandColumn1" />
    </EditFormSettings>
</MasterTableView>
<ClientSettings EnableRowHoverStyle="false" >
    <Selecting AllowRowSelect="True"  />
</ClientSettings>
</telerik:radgrid>


This is my UserControl:
<div style="float: left; width: 965px;">
    <div style="width: 255px; height: 200px; float: left; margin: 10px 0px 0px 20px; font-family: Tahoma, Arial, Helvetica; font-size: 12px; font-weight: normal; color: #000000;">
        <div style="float: left; width: 255px;">
            <asp:Label ID="lblContactName" runat="server" Text='<%# DataBinder.Eval( Container, "DataItem.ContactName" ) %>' /> <br />
            <asp:Label ID="lblContactStreetAddress" runat="server" Text='<%# DataBinder.Eval( Container, "DataItem.ContactStreetAddress" ) %>' /> <br />
            <asp:Label ID="lblContactCity" runat="server" Text='<%# DataBinder.Eval( Container, "DataItem.ContactCity" ) + ", " + DataBinder.Eval( Container, "DataItem.ContactState" ) + " " + DataBinder.Eval( Container, "DataItem.ContactZip" ) %>' />
        </div>  
        <div style="float: left; width: 100px; margin: 10px 0px 0px 0px;">
            <span style="color: #949494;">Phone:</span> <br />
            <asp:Label ID="lblContactPhone" runat="server" Text='<%# DataBinder.Eval( Container, "DataItem.ContactPhone" ) %>' />
        </div>
        <div style="float: left; width: 100px; margin: 10px 0px 0px 0px;">
            <span style="color: #949494;">Mobile Phone:</span> <br />
            <asp:Label ID="lblContactMobilePhone" runat="server" Text='<%# DataBinder.Eval( Container, "DataItem.ContactMobilePhone" ) %>' />
        </div>
        <div style="float: left; width: 200px; margin: 10px 0px 0px 0px;">
            <span style="color: #949494;">Email:</span> <br />
            <asp:Label ID="Label1" runat="server" Text='<%# DataBinder.Eval( Container, "DataItem.ContactEmail" ) %>' />
        </div>
        <div style="float: left; width: 200px; margin: 10px 0px 0px 0px;">
            <span style="color: #949494;">Source:</span> <br />
            <asp:Label ID="Label2" runat="server" Text='<%# DataBinder.Eval( Container, "DataItem.Source" ) %>' />
        </div>       
    </div>
     
    <div style="float: left; width: 285px; margin: 10px 0px 0px 0px;">
        <span style="color: #949494; font-size: 12px; font-family: Tahoma, Arial, Helvetica;">Notes:</span> <br />
        <telerik:RadTextBox Width="250px" Height="75px" ID="radTextBoxNotes" runat="server" TextMode="MultiLine" Label="" Text="">
        </telerik:RadTextBox>
         
        <div style="float: left; margin: 10px 0px 0px 148px;">
            <asp:ImageButton ID="imgBtnSaveNote" runat="server" ImageUrl="~/images/saveNoteBtn.png" onclick="imgBtnSaveNote_Click" OnClientClick="Rebind();" />
        </div>   
        <div style="float: left; width: 250px;">
            <asp:Label ID="lblNotesHistory" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.Notes").ToString().Replace("\r\n", "<br>") %>' style="color: #000000; font-size: 12px; font-family: Arial, Helvetica;" Width="250px" />
        </div
          
    </div>
    <div style="float: left; width: 400px; margin: 10px 0px 0px 0px; height: 300px;">
        <div style="float: left; color: #949494; font-size: 12px; font-family: Tahoma, Arial, Helvetica; width: 300px;">
            Evaluation:
        </div>
        <div style="float: left; width: 400px;">
            <div style="float: left; width: 50px; color: #92d050; font-size: 38px; font-family: Arial, Helvetica; font-weight: bold; height: 90px; line-height: normal;">
                <asp:Label ID="lblEvalRating" runat="server" Text='<%# Eval("Eval").ToString().Substring(0, 2) %>' onprerender="lblEvalRating_PreRender" />
            </div>
            <div style="float: left; width: 345px;">
                <asp:RadioButtonList RepeatDirection="Vertical" Width="345px" CellPadding="0" CellSpacing="0" ID="rblChangeButtonType" runat="server" AutoPostBack="False" SelectedValue='<%# Bind("EvalVal") %>'>
                    <asp:ListItem Value="100000000" Text="No Evaluation Yet" />
                    <asp:ListItem Value="100000001" Text="A - Existing application, ready to move on purchase" />
                    <asp:ListItem Value="100000002" Text="B - Pending application, strong interest in Colder technology" />
                    <asp:ListItem Value="100000003" Text="C - Interested but no immediate need" />
                    <asp:ListItem Value="100000005" Text="F - Close lead, no potential" />
                </asp:RadioButtonList>
            </div>
            <div style="float: left; width: 115px; margin: 10px 0px 0px 50px;">             
                <span style="color: #949494; font-size: 12px; font-family: Tahoma, Arial, Helvetica;">Est. Close Date:</span> <br />
                <telerik:RadDatePicker ID="RadDatePicker1" runat="server" ZIndex="30001" DbSelectedDate='<%# Bind("EstimatedCloseDate") %>' Width="115px" />
            </div>
            <div style="float: left; width: 100px; margin: 10px 0px 0px 10px;">             
                <span style="color: #949494; font-size: 12px; font-family: Tahoma, Arial, Helvetica;">Maturity Value:</span> <br />
                <asp:TextBox ID="textBoxMaturityValue" runat="server" Text='<%# DataBinder.Eval( Container, "DataItem.MaturityValue" ) %>' Width="85px" />
            </div>                             
        </div>
        <div style="float: left; width: 103px; margin: 10px 0px 0px 75px;">
            <a href="#dialog" name="modal"><img src="/images/backBtn.png" alt="Back" style="border: 0px;" /></a>
        </div>
        <div style="float: left; width: 76px; margin: 10px 0px 0px 10px;">
            <asp:ImageButton ID="imgBtnSaveAll" runat="server" ImageUrl="~/images/btnSaveAll.png" onclick="imgBtnSaveAll_Click" />
        </div>       
    </div>
</div>
<telerik:RadInputManager ID="RadInputManager1" runat="server">
    <telerik:NumericTextBoxSetting BehaviorID="NumericBehavior1" EmptyMessage="$" Type="Currency" Validation-IsRequired="false">
        <TargetControls>
            <telerik:TargetInput ControlID="textBoxMaturityValue" />
        </TargetControls>
    </telerik:NumericTextBoxSetting>
</telerik:RadInputManager>

1 Answer, 1 is accepted

Sort by
0
Accepted
Shinu
Top achievements
Rank 2
answered on 13 Sep 2011, 01:18 PM
Hello Justin,

I guess you don't want to close the edit form after the update operation. If so you can try the following code snippet .

ASPX:
<telerik:RadGrid ID="RadGrid" runat="server"
            DataSourceID="SqlDataSource1" onupdatecommand="RadGrid_UpdateCommand"
            onprerender="RadGrid_PreRender">
            <MasterTableView CommandItemDisplay="Top" DataKeyNames="EmployeeID" EditMode="PopUp">
                <Columns>
                   .  .   .   .
                </Columns>
                <EditFormSettings EditFormType="WebUserControl" UserControlName="~/RadGrid/WebUserControl_Edit.ascx">
                    <FormTemplate>
                    </FormTemplate>
                </EditFormSettings>
            </MasterTableView>
 </telerik:RadGrid>

C#:
int index = -1;
bool flag = false;
 
protected void RadGrid_UpdateCommand(object sender, GridCommandEventArgs e)
{
    GridEditFormItem editedItem = (GridEditFormItem)e.Item;
    index = editedItem.ItemIndex;
    UserControl userControl = (UserControl)editedItem.FindControl(GridEditFormItem.EditFormUserControlID);
    //update operation
    flag = true;
}
protected void RadGrid_PreRender(object sender, EventArgs e)
{
    if (flag)
    {
        GridDataItem item = (GridDataItem)RadGrid.Items[index];
        item.Edit = true;
        RadGrid.Rebind();
    }
}

-Shinu.
Tags
Grid
Asked by
Justin
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Share this question
or