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

Radgrid Insert/Update command

1 Answer 450 Views
Grid
This is a migrated thread and some comments may be shown as answers.
LevizBB
Top achievements
Rank 1
LevizBB asked on 02 May 2012, 01:19 PM
Hello,

We couldn't fire our Insert/Update command int the RadGrid when editing the row.
We have tried almost every solutions given on this forum without success.

Some information about our code situation :
 - The code is in a Web Controls (details.ascx)
 - We have disabled Ajax
 - The code is in a RadPageView, that is in an UpdatePanel
 
 The code from ASP.NET
<telerik:RadGrid ID="__linksRadGrid" runat="server"
        AllowMultiRowEdit="false"
        ShowStatusBar="true"
        GridLines="None"
        AllowPaging="False"  
        AllowAutomaticUpdates="false"
        AllowAutomaticInserts="false"
        OnNeedDataSource="LinksRadGrid_NeedDataSource"                      
        OnInsertCommand="LinksRadGrid_InsertCommand"
        OnUpdateCommand="LinksRadGrid_UpdateCommand"
        OnDeleteCommand="LinksRadGrid_DeleteCommand"
        OnItemDataBound="LinksRadGrid_ItemDataBound"
        OnItemCommand="LinksRadGrid_ItemCommand"
        AllowSorting="true"
        Skin="Transparent"
        Width="450px">
    <MasterTableView AutoGenerateColumns="False"
            DataKeyNames="IdAttachment"
            CommandItemDisplay="Bottom" >
        <PagerStyle Mode="NextPrevAndNumeric" />
        <CommandItemTemplate>
            <div style="padding: 5px 5px;">
                <asp:ImageButton ID="imgInsert" runat="server"
                        ImageUrl="~/App_Themes/Default/Images/Icons/add2.gif"
                        CommandName="InitInsert"
                        AlternateText="Insert New Record"                
                        ToolTip = "Insert New Record" />
                  
                <asp:ImageButton ID="imgRefresh" runat="server"
                        ImageUrl="~/App_Themes/Default/Images/Icons/refresh.png"
                        CommandName="RebindGrid"
                        AlternateText="Refresh the grid"                
                        ToolTip = "Refresh the grid" />
            </div>
        </CommandItemTemplate>
        <Columns>
            <telerik:GridEditCommandColumn ButtonType="ImageButton" />
 
            <telerik:GridBoundColumn DataField="Title"
                    DataType="System.String"
                    HeaderText="Title"
                    SortExpression="Title"
                    UniqueName="Title">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn DataField="Description"
                    DataType="System.String"
                    HeaderText="Description"
                    SortExpression="Description"
                    UniqueName="Description">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn DataField="AttachmentType"
                    DataType="System.String"
                    HeaderText="AttachmentType"
                    SortExpression="AttachmentType"
                    UniqueName="AttachmentType"
                    Display="false">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn DataField="Url"
                    DataType="System.String"
                    HeaderText="Url"
                    SortExpression="Url"
                    UniqueName="URL"
                    Display="false">
            </telerik:GridBoundColumn>
            <telerik:GridTemplateColumn 
                    HeaderText="Type" 
                    UniqueName="Type">
                <ItemTemplate>
                    <asp:ImageButton ID="__attachedTypeImageButton" runat="server" />
                </ItemTemplate>
            </telerik:GridTemplateColumn>
 
            <telerik:GridButtonColumn CommandName="Delete" ButtonType="ImageButton"
                    ConfirmText="Delete this record?"
                    ConfirmDialogType="RadWindow"
                    ConfirmTitle="Delete" />
 
        </Columns>
        <EditFormSettings EditFormType="Template">
            <EditColumn UniqueName="EditCommandColumn1">
            </EditColumn>
            <FormTemplate>
                <table cellspacing="2" cellpadding="1" width="100%" border="0">
                    <tr>
                        <td>
                            <asp:Label ID="__titleLabel" runat="server"
                                    Text="Title">
                            </asp:Label>
                        </td>
                        <td>
                            <asp:TextBox ID="_titleTextBox" runat="server"
                                    Width="100px"
                                    Text='<%# Bind("Title") %>' >
                            </asp:TextBox>
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <asp:Label ID="__decriptionLabel" runat="server"
                                    Text="Description">
                            </asp:Label>
                        </td>
                        <td>
                            <asp:TextBox ID="__decriptionTextBox" runat="server"
                                    Width="100px"
                                    TextMode="MultiLine"
                                    Rows="4"
                                    Text='<%# Bind("Description") %>'>
                            </asp:TextBox>
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <asp:Label ID="__URLLabel" runat="server"
                                    Text="URL">
                            </asp:Label>
                        </td>
                        <td>
                            <asp:TextBox ID="__urlTextBox" runat="server"
                                    Width="255px"
                                    Text='<%# Bind("URL") %>' >
                            </asp:TextBox>
                        </td>
                    </tr>
                    <tr>
                        <td colspan="2">
                            <asp:Label ID="__orLabel" runat="server"
                                    Text="or">
                            </asp:Label>
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <asp:Label ID="__fileUploadLabel" runat="server"
                                    Text="File">
                            </asp:Label>
                        </td>
                        <td>
                            <asp:FileUpload ID="__fileUpload" runat="server" />
                        </td>
                    </tr>
                    <tr>
                         <td align="right" colspan="2">
                            <asp:Button ID="btnUpdate" runat="server"
                                    Text='<%# (Container is GridEditFormInsertItem) ? "Insert" : "Update" %>'
                                    CommandName='<%# (Container is GridEditFormInsertItem) ? "PerformInsert" : "Update" %>'
                                    CausesValidation="True" >
                            </asp:Button
                              
                            <asp:Button  ID="btnCancel" runat="server"
                                    Text="Cancel"
                                    CausesValidation="False"
                                    CommandName="Cancel">
                            </asp:Button >
                        </td>
                    </tr>
                </table>
            </FormTemplate>
        </EditFormSettings>
    </MasterTableView>
</telerik:RadGrid>

The C# code of code-behind
protected void LinksRadGrid_NeedDataSource(object sender, GridNeedDataSourceEventArgs e) {
     
    List<Attachment> attachmentList = AttachmentBLL.GetByIdDocument(this.IdDocument);
    DataTable dt = this.ToDataTable<Attachment>(attachmentList);
 
    __linksRadGrid.DataSource = dt;
}
 
protected void LinksRadGrid_ItemDataBound(object sender, GridItemEventArgs e) {
 
    if (e.Item is GridDataItem) {
        GridDataItem gridDataItem = (GridDataItem)e.Item;        
 
        int attachedType = int.Parse(gridDataItem["AttachmentType"].Text);
        ImageButton image = (ImageButton)gridDataItem["Type"].FindControl("__attachedTypeImageButton");
         
        if (attachedType == 4
                && !string.IsNullOrEmpty(gridDataItem["URL"].Text)) {
 
            image.ImageUrl = "~/App_Themes/Default/Images/Icons/web.png";
            image.OnClientClick = this.WindowsOpenPopup(gridDataItem["URL"].Text);
        }
        else if (attachedType == 5) { // Type document
                         
            int idAttachment = int.Parse(gridDataItem["IdAttachment"].Text);
                             
            image.ImageUrl = "~/App_Themes/Default/Images/Icons/pdf16.png";
            image.OnClientClick = this.GetAttachmentLinksUrl(idAttachment);
        }
        else {
 
            this.ShowImageError(image, "Error : wrong data error! Please correct your data.");               
        }
    }
}
 
 
protected void LinksRadGrid_ItemCommand(object source, GridCommandEventArgs e) {
 
    if (e.CommandName == "Update" && e.Item is GridEditFormItem) {
        GridEditFormItem editFormItem = (GridEditFormItem)e.Item;
    }
}
 
protected void LinksRadGridUpdate_Click(object sender, EventArgs e) {
 
    if (IsPostBack) {
 
    }
 
}
 
protected void LinksRadGrid_InsertCommand(object sender, GridCommandEventArgs e) {
 
    GridEditableItem editedItem = e.Item as GridEditableItem;
}
 
protected void LinksRadGrid_UpdateCommand(object sender, GridCommandEventArgs e) {
 
    if (e.CommandName == RadGrid.UpdateCommandName) {
        if (e.Item is GridEditFormItem) {
            GridEditFormItem item = (GridEditFormItem)e.Item;
        }
    }
}
protected void LinksRadGrid_DeleteCommand(object sender, GridCommandEventArgs e) {
 
    GridEditableItem editedItem = e.Item as GridEditableItem;
}
 



Thank for your help



1 Answer, 1 is accepted

Sort by
0
LevizBB
Top achievements
Rank 1
answered on 02 May 2012, 05:16 PM
I resolve the problem : I updated the Telerik references to the last version and everything work fine.

Old version : 2011.3.1115.40
New version : 2012.1.501.40

I couldn't close this ticket. If an admin could do it, it will be great.

Thanks
Tags
Grid
Asked by
LevizBB
Top achievements
Rank 1
Answers by
LevizBB
Top achievements
Rank 1
Share this question
or