Telerik Forums
UI for ASP.NET AJAX Forum
1 answer
192 views
Hi
I have a RadGrid which uses custom data binding (and of course custom paging and sorting). here is the markup:

<telerik:RadGrid runat="server" ID="grdArticoliCommentabili"
        AutoGenerateColumns="false" AllowPaging="true"
        OnItemCommand="grdArticoliCommentabili_ItemCommand"
        OnDetailTableDataBind="grdArticoliCommentabili_DetailTableDataBind"
        OnItemDataBound="grdArticoliCommentabili_ItemDataBound"
        AllowFilteringByColumn="true"
        OnPageIndexChanged="grdArticoliCommentabili_PageIndexChanged"
        OnPageSizeChanged="grdArticoliCommentabili_PageSizeChanged">
        <GroupingSettings CaseSensitive="false" />
        <MasterTableView DataKeyNames="id_articolo" CommandItemDisplay="Top" NoMasterRecordsText="<%$ Resources:Labels,NessunDato %>"
            NoDetailRecordsText="<%$ Resources:Labels,NessunDato %>">
            <CommandItemTemplate>
                <table cellpadding="4" cellspacing="0" width="100%">
                    <tr>
                        <td style="text-align: right; vertical-align: bottom;">
                            <asp:LinkButton ID="btnAggiorna" runat="server" CommandName="RebindGrid" CssClass="btnAggiorna">
                                <asp:Localize ID="Localize1" runat="server" Text="<%$ Resources:Labels,Refresh %>" />
                            </asp:LinkButton>
                            <asp:LinkButton ID="btnGestioneBan" runat="server" OnClientClick="manageBans(); return false;" CssClass="btnAggiungi">
                                <asp:Localize ID="Localize2" runat="server" Text="<%$ Resources:,GestisciBan %>" />
                            </asp:LinkButton>
                        </td>
                    </tr>
                </table>
            </CommandItemTemplate>
            <CommandItemStyle Height="25px" />
            <Columns>
                <telerik:GridTemplateColumn HeaderText="<%$ Resources:Grids,Commenti_Articolo %>" DataField="titolo"
                    UniqueName="titolo" AllowFiltering="true" CurrentFilterFunction="Contains" CurrentFilterValue=""
                    ShowFilterIcon="false" SortExpression="titolo" AutoPostBackOnFilter="True" FilterControlWidth="400px">
                    <ItemTemplate>
                        <asp:Label runat="server" ID="lbl_titolo" Text='<%# Eval("titolo") %>' />
                    </ItemTemplate>
                    <ItemStyle Width="500px" />
                </telerik:GridTemplateColumn>
                <telerik:GridTemplateColumn HeaderText="<%$ Resources:Grids,Commenti_Pubblicati %>" UniqueName="pubblicati"
                    AllowFiltering="false">
                    <ItemTemplate>
                        <a href="" onclick='<%# "showPublishedComments(" + Eval("id_articolo").ToString() + "); return false;" %>' class="lblRimbalzi">
                            <asp:Label runat="server" ID="lbl_pubblicati" Text='' /></a>
                    </ItemTemplate>
                    <ItemStyle Width="100px" />
                </telerik:GridTemplateColumn>
                <telerik:GridTemplateColumn HeaderText="<%$ Resources:Grids,Commenti_DaApprovare %>"
                    UniqueName="daapprovare" AllowFiltering="false">
                    <ItemTemplate>
                        <asp:Label runat="server" ID="lbl_da_approvare" Text='' />
                    </ItemTemplate>
                    <ItemStyle Width="100px" />
                </telerik:GridTemplateColumn>
            </Columns>
            <DetailTables>
                <telerik:GridTableView Name="Commenti" runat="server" DataKeyNames="id_commento" AutoGenerateColumns="false"
                    AllowPaging="true" AllowSorting="true" AllowFilteringByColumn="false" PageSize="5"
                    NoMasterRecordsText="<%$ Resources:Labels,NessunDato %>" NoDetailRecordsText="<%$ Resources:Labels,NessunDato %>">
                    <Columns>
                        <telerik:GridTemplateColumn HeaderText="" UniqueName="commento" AllowFiltering="false">
                            <ItemTemplate>
                                <table>
                                    <tr>
                                        <td>
                                            <asp:Label runat="server" Text="<%$ Resources:,ID %>" />
                                        </td>
                                        <td>
                                            <asp:Label runat="server" ID="lbl_id_commento" Text='<%# Eval("id_commento") %>' />
                                        </td>
                                    </tr>
                                    <tr>
                                        <td>
                                            <asp:Label runat="server" Text="<%$ Resources:,Autore %>" />
                                        </td>
                                        <td>
                                            <asp:Label runat="server" ID="lbl_autore" Text='<%# GetCommentAuthor((Commento)Container.DataItem) %>' />
                                        </td>
                                    </tr>
                                    <tr>
                                        <td>
                                            <asp:Label ID="Label1" runat="server" Text="<%$ Resources:,Email %>" />
                                        </td>
                                        <td>
                                            <asp:Label runat="server" ID="Label3" Text='<%# Eval("email") %>' />
                                        </td>
                                    </tr>
                                    <tr>
                                        <td>
                                            <asp:Label runat="server" Text="<%$ Resources:,Data %>"></asp:Label>
                                        </td>
                                        <td>
                                            <asp:Label runat="server" ID="lbl_dataregistrazione" Text='<%# Eval("dataregistrazione","{0:g}") %>' />
                                        </td>
                                    </tr>
                                    <tr>
                                        <td>
                                            <asp:Label runat="server" Text="<%$ Resources:,Oggetto %>" />
                                        </td>
                                        <td>
                                            <asp:Label runat="server" ID="lbl_oggetto" Text='<%# GetCommentSubject(Eval("oggetto").ToString()) %>' />
                                        </td>
                                    </tr>
                                    <tr>
                                        <td>
                                            <asp:Label runat="server" Text="<%$ Resources:,Messaggio %>" />
                                        </td>
                                        <td>
                                            <asp:Literal Mode="PassThrough" runat="server" ID="lbl_messaggio" Text='<%# GetCommentBody(Eval("body").ToString()) %>' />
                                        </td>
                                    </tr>
                                    <tr>
                                        <td colspan="2">
                                            <asp:LinkButton ID="btnApprova" CommandName="ApproveComment" runat="server" Text="<%$ Resources:,Approva %>" CssClass="btnAnnulla_Click" />
                                              
                                            
                                            <asp:LinkButton ID="btnCancella" OnClientClick='<%# GenerateDeleteScript() %>' CommandName="DeleteComment" runat="server" Text="<%$ Resources:Labels,Elimina %>" CssClass="btnElimina" />
                                        </td>
                                    </tr>
                                </table>
                            </ItemTemplate>
                        </telerik:GridTemplateColumn>
                    </Columns>
                </telerik:GridTableView>
            </DetailTables>
            <PagerStyle AlwaysVisible="true" PageSizes="10" />
        </MasterTableView>
    </telerik:RadGrid>

In the backend I have the following code which is executed in Page_Load:

protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
            BindGrid();
    }
 
    private void BindGrid()
    {
        CommentiController controller = new CommentiController();
        grdArticoliCommentabili.DataSource = controller.SelectCommentableArticles("CommentiArticolo");
        grdArticoliCommentabili.DataBind();
    }
 
    private void ReloadCommentsGrid(GridEditableItem item)
    {
        CommentiController controller = new CommentiController();
        var id_articolo = (int)item.OwnerTableView.ParentItem.GetDataKeyValue("id_articolo");
        item.OwnerTableView.DataSource = controller.SelectNonApprovedCommentsByArticle(id_articolo, "Utente");
        item.OwnerTableView.DataBind();
    }
 
    private void LoadCommentsGrid(GridTableView view)
    {
        CommentiController controller = new CommentiController();
        int id_articolo = (int)view.ParentItem.GetDataKeyValue("id_articolo");
        view.DataSource = controller.SelectNonApprovedCommentsByArticle(id_articolo, "Utente");
    }
 
    protected void grdArticoliCommentabili_ItemCommand(object source, GridCommandEventArgs e)
    {
        if (e.CommandName == RadGrid.RebindGridCommandName || e.CommandName == RadGrid.FilterCommandName)
        {
            BindGrid();
        }
        else if (e.CommandName == "ApproveComment")
        {     
            var item = e.Item as GridEditableItem;
            var id_commento = (int)item.GetDataKeyValue("id_commento");
 
            if (!JPortalUserBag.HasPermission(Entities.Commento, Permissions.Edit, Entities.NoEntityID))
            {
                SetError(GetGlobalString("Errors", "SicurezzaPermessiInsufficentiOperazione"));
                LogManager.WriteWarning(GetLogSubject(), GetGlobalString("Errors", "SicurezzaPermessiInsufficentiOperazione"));
                BindGrid();
                return;
            }
 
            try
            {
                CommentiController controller = new CommentiController();
                var commento = controller.SelectByID(id_commento);
                commento.approvato = true;
 
                var parent_item = item.OwnerTableView.ParentItem;
 
                var lbl_pubblicati = (parent_item["pubblicati"].FindControl("lbl_pubblicati") as Label);
                var lbl_da_approvare = (parent_item["daapprovare"].FindControl("lbl_da_approvare") as Label);
 
                int parent_pubblicati = Convert.ToInt32(lbl_pubblicati.Text);
                int parent_daapprovare = Convert.ToInt32(lbl_da_approvare.Text);
 
                parent_pubblicati++;
                parent_daapprovare--;
 
                lbl_pubblicati.Text = parent_pubblicati.ToString();
                lbl_da_approvare.Text = parent_daapprovare.ToString();
 
                controller.Update(commento, false);
                ReloadCommentsGrid(item);
 
                LogManager.WriteMessage(GetLogSubject(), GetGlobalString("Messages", "CommentoApprovazione").Arguments(id_commento.ToString()));
                SetMessage(GetGlobalString("Messages", "CommentoApprovazione").Arguments(id_commento.ToString()));
            }
            catch (Exception)
            {
                LogManager.WriteError(GetLogSubject(), GetGlobalString("Errors", "CommentoApprovazione").Arguments(id_commento.ToString()));
                SetError(GetGlobalString("Errors", "CommentoApprovazione").Arguments(id_commento.ToString()));
                throw;
            }
        }
        else if (e.CommandName == "DeleteComment")
        {
            var item = e.Item as GridEditableItem;
            var id_commento = (int)item.GetDataKeyValue("id_commento");
 
            if (!JPortalUserBag.HasPermission(Entities.Commento, Permissions.Delete, Entities.NoEntityID))
            {
                SetError(GetGlobalString("Errors", "SicurezzaPermessiInsufficentiOperazione"));
                LogManager.WriteWarning(GetLogSubject(), GetGlobalString("Errors", "SicurezzaPermessiInsufficentiOperazione"));
                BindGrid();
                return;
            }
 
            try
            {
                CommentiController controller = new CommentiController();
                var commento = controller.SelectByID(id_commento);
 
                var parent_item = item.OwnerTableView.ParentItem;
                var lbl_da_approvare = (parent_item["daapprovare"].FindControl("lbl_da_approvare") as Label);
                int parent_daapprovare = Convert.ToInt32(lbl_da_approvare.Text);
 
                lbl_da_approvare.Text = (--parent_daapprovare).ToString();
 
                controller.Delete(commento, false);
                ReloadCommentsGrid(item);
 
                LogManager.WriteMessage(GetLogSubject(), GetGlobalString("Messages", "CommentoEliminazione").Arguments(id_commento.ToString()));
                SetMessage(GetGlobalString("Messages", "CommentoEliminazione").Arguments(id_commento.ToString()));
 
            }
            catch (Exception)
            {
                LogManager.WriteError(GetLogSubject(), GetGlobalString("Errors", "CommentoEliminazione").Arguments(id_commento.ToString()));
                SetError(GetGlobalString("Errors", "CommentoEliminazione").Arguments(id_commento.ToString()));
                throw;
            }
        }
    }
 
    protected string GetCommentSubject(string input)
    {
        if (String.IsNullOrEmpty(input))
        {
            return GetLocalString("CommentoOggettoEliminato");
        }
        else
        {
            return input;
        }
    }
 
    protected string GetCommentBody(string input)
    {
        if (String.IsNullOrEmpty(input))
        {
            return GetLocalString("CommentoEliminato");
        }
        else
        {
            return input;
        }
    }
 
    protected string GetCommentAuthor(Commento comm)
    {
        if (comm.nome != null && comm.cognome != null)
            return String.Concat(comm.nome, " ", comm.cognome);
        else
            return comm.Utente != null ? comm.Utente.login : String.Empty;
    }
 
    protected string GenerateDeleteScript()
    {
        return "return showDoublePrompt('{0}',null);".Arguments(GetJSString(GetGlobalString("Messages", "MessaggioEliminazione")));
    }
 
    private string GetJSString(string input)
    {
        return input.Replace("'", "\'");
    }
 
    protected void grdArticoliCommentabili_DetailTableDataBind(object source, GridDetailTableDataBindEventArgs e)
    {
        LoadCommentsGrid(e.DetailTableView);
    }
 
    protected void grdArticoliCommentabili_ItemDataBound(object sender, GridItemEventArgs e)
    {
        if (e.Item is GridEditableItem)
        {
            var item = e.Item as GridEditableItem;
            var articolo = item.DataItem as Articolo;
            if (item.OwnerTableView.Name == "Commenti") return;
 
            var lbl_pubblicati = (item["pubblicati"].FindControl("lbl_pubblicati") as Label);
            var lbl_da_approvare = (item["daapprovare"].FindControl("lbl_da_approvare") as Label);
 
            var totale_commenti = articolo.CommentiArticolo.Where(a => a.approvato == true).Count();
            var da_approvare = articolo.CommentiArticolo.Where(a => a.approvato == false).Count();
 
            lbl_pubblicati.Text = totale_commenti.ToString();
            lbl_da_approvare.Text = da_approvare.ToString();
        }
    }
 
    protected void grdArticoliCommentabili_PageIndexChanged(object source, GridPageChangedEventArgs e)
    {
        BindGrid();
    }
 
    protected void grdArticoliCommentabili_PageSizeChanged(object source, GridPageSizeChangedEventArgs e)
    {
        BindGrid();
    }

The problem is that when "DataBind" method is executed in "BindGrid" (called by Page_Load) also the PageSizeChanged event is raised, which, in turn causes the "BindGrid" method to be recalled, which again, raises the PageSizeChanged event and so on... until the StackOverflowException is raised... Can I know why "PageSizeChanged" is raised when I call "DataBind"?

* UPDATE * 
I want to add that the PageSizeChanged event is raised not one time, but five: equal to the number of rows in the MasterTableView.

Thank you!
Andrey
Telerik team
 answered on 10 Apr 2013
1 answer
124 views
I have download the Telerik Trail version and tried to use RadGrid. I can able to bind datatable from codebehind but able to execute code on any other grid event like onItemUpdate, onItemDelete and etc. Please check code below 

CodeBehind

 public void gwList_Delete(object sender, Telerik.Web.UI.GridItemEventArgs e)
    {
        
        if (!(new BusinessLogic.LogicClasses.clsUser()).validatePage(Convert.ToInt64(Session["UserID"].ToString()), Page.GetType().Name.Replace("_", "."), BusinessLogic.clsGeneral.RecActionDelete))
        {
            Response.Redirect("Default.aspx?msg=" + BusinessLogic.clsGeneral.strUnAutherise, true);
        }
        else
        {
            BusinessLogic.EntityClasses.clsCity objEDel = new BusinessLogic.EntityClasses.clsCity();
            //objEDel.RecID = Convert.ToInt64(gwList.data[e.Item].Values[0].ToString());
            objEDel.RUserID = Convert.ToInt64(Session["UserID"].ToString());
            long lrt = (new BusinessLogic.LogicClasses.clsCity()).Delete(objEDel);
            if (lrt > 0)
                (new clsFunctions()).SetMessage(BusinessLogic.clsGeneral.strSuccess, Master);
            else
                (new clsFunctions()).SetMessage(BusinessLogic.clsGeneral.strUnSuccess, Master);

            LoadGrid();
        }



ASPX:
 <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">
        <AjaxSettings>
            <telerik:AjaxSetting AjaxControlID="gwList">
                <UpdatedControls>
                    <telerik:AjaxUpdatedControl ControlID="gwList" />
                </UpdatedControls>
            </telerik:AjaxSetting>
            <telerik:AjaxSetting AjaxControlID="RadGrid2">
                <UpdatedControls>
                    <telerik:AjaxUpdatedControl ControlID="RadGrid2" LoadingPanelID="RadAjaxLoadingPanel1" />
                </UpdatedControls>
            </telerik:AjaxSetting>
        </AjaxSettings>
    </telerik:RadAjaxManager>
    <telerik:RadAjaxLoadingPanel ID="RadAjaxLoadingPanel2" runat="server" />
   

    <telerik:RadGrid ID="gwList" EnableViewState="true" runat="server" AllowPaging="true"
        AllowSorting="True" AllowFilteringByColumn="false" GridLines="None"
         AutoGenerateColumns="false" AllowAutomaticDeletes="true"
            OnItemDeleted="gwList_delete">
        
        <MasterTableView AllowMultiColumnSorting="true" TableLayout="Fixed" EditMode="EditForms"
         AllowFilteringByColumn="true" DataSourceID="" AllowPaging="true">
            <Columns>
                <telerik:GridBoundColumn DataField="City" HeaderText="City" HeaderStyle-Width="100px"
                    FilterControlWidth="50px" AllowFiltering="true">
                </telerik:GridBoundColumn>
                <telerik:GridBoundColumn DataField="Country" HeaderText="Country" AllowFiltering="true">
                </telerik:GridBoundColumn>
                <telerik:GridBoundColumn DataField="Miki" HeaderText="Miki" AllowFiltering="true">
                </telerik:GridBoundColumn>
      
        <telerik:GridButtonColumn ConfirmText="Delete this product?" ConfirmDialogType="RadWindow"
                    ConfirmTitle="Delete" ButtonType="ImageButton" CommandName="Delete" Text="Delete"
                    UniqueName="Miki"  >

                    <ItemStyle HorizontalAlign="Center" CssClass="MyImageButton"></ItemStyle>
                </telerik:GridButtonColumn>



        <telerik:GridEditCommandColumn >
        </telerik:GridEditCommandColumn>
    


            </Columns>
        </MasterTableView>
        
    </telerik:RadGrid>
    <telerik:RadAjaxLoadingPanel ID="RadAjaxLoadingPanel1" runat="server">
    </telerik:RadAjaxLoadingPanel>
Kostadin
Telerik team
 answered on 10 Apr 2013
1 answer
58 views
We've run into a couple problems with Preview mode of the editor. The editor version is 2012.2.724.40.

First problem:

Switching the editor to Preview mode, then back to design/html mode, onclick of an anchor tag has been removed. Example:

  <a href="http://www.google.com" onclick="alert('clicked');">link</a>

changed to:

  <a href="http://www.google.com">link</a>


Second problem:

Switching the editor to Preview mode and submitting the page, target="blank" has been added to the anchor tag. Example:

  <a href="http://www.google.com">link</a>

changed to:

  <a target="blank" href="http://www.google.com">link</a>


Are these known issues in version 2012.2.724.40 of the editor?

Dobromir
Telerik team
 answered on 10 Apr 2013
0 answers
110 views
Hi,

I would like to implement grouping of radgrid concept in DynamicRadGrid. Is it possible to implement it with dynamicdata along with DynamicRadGrid or simply in RadGrid? If so, please provide me some example url, so that i can go through it.
 
Please provide me some guidelines, as i didnot found related links in my search.

Sujith
Top achievements
Rank 1
 asked on 10 Apr 2013
1 answer
140 views
Hi

How to set the font as well as selected item background color from javascript?

Thanks,
Dona
Princy
Top achievements
Rank 2
 answered on 10 Apr 2013
1 answer
230 views
Hi,

When I am setting the navigateurl to yahoo, the radwindow is opened but the url is not loaded. But if i give some other domain like telerik.com, its working.

Thanks,
Dona
Princy
Top achievements
Rank 2
 answered on 10 Apr 2013
1 answer
90 views
Hello !

i want to add detail table to grid using the s_number as the relation to get the data in the detail table

thx in advance
Shinu
Top achievements
Rank 2
 answered on 10 Apr 2013
1 answer
431 views
Hi,

I need to loop thru radgrid columns and if they allow update, I need to make it as read only. My grid has mixed type of columns with bound columns and Template columns with Textboxes. All the columns in grid are readonly except Template columns. We allow user to enter data into textboxes. Under certain logic, I need to make entire grid as read only.  This check needs to be done out of Radgrid events.
something like this:
foreach (GridColumn gc in RadGrid1.Columns)
{
        if (gc.AllowUpdate == true)
             gc.AllowUpdate = false;

             gc.cell.style = "disablecell";
}
Please let me know how to do it.

T
Shinu
Top achievements
Rank 2
 answered on 10 Apr 2013
7 answers
115 views
I have a grid with fixed height and no paging and allow scroll TRUE.
The grid also has nested detail tables.
In Firefox 10 SaveScrollPosition works as expected, but IE8 it doesn't.
When I open a detail table near the bottom of the grid, in IE8 the grid opens correctly but then scrolls to the top.
I'm using Q1 2012 controls.
Pavlina
Telerik team
 answered on 09 Apr 2013
1 answer
113 views
Hi All,

I have modified the Custom DB Provider to read from a table with records of folders and files.
Each record has a column with the full path versus the demo which has each folder separated.

My modifications have not deviated to any great extent from the original demo.

The problem I am encountering is that the ResolveDirectory is called only once following the initial call of ResolveRootDirectoryAsTree.

All of the folders render and the ResolveRootDirectoryAsTree is called whenever a folder is first expanded.

ResolveDirectory does not fire when folders are expanded and no files are shown.

Each Folder is loaded into a Directory Item:

name "mySubfolder
fullpath "Root/myFolder/mySubfolder/"
location "Root/myFolder/"
tag String.Empty,
permissions PathPermissions.Read
File Items null for ResolveRootDirectoryAsTree, populated for ResolveDirectory
Directory Items null for ResolveDirectory, populated for ResolveRootDirectoryAsTree

Each File is loaded into a File Item:

filename "myfile.jpg"
extension ".jpg"
size int64
path "Root/myFolder/mySubfolder/myfile.jpg"
filehandlerURL "..."
tag String.Empty
permissions PathPermissions.Read

I can post a snippet if need be, but I was wondering if anyone has encountered this or if the above structure is incorrect before I do so.

The downloaded Custom DB Provider works fine, only the modified copy has this issue.


Cheers,





Tim
Top achievements
Rank 1
 answered on 09 Apr 2013
Narrow your results
Selected tags
Tags
+? more
Top users last month
Grant
Top achievements
Rank 3
Iron
Iron
Iron
Dean
Top achievements
Rank 1
Leland
Top achievements
Rank 2
Iron
Iron
Iron
Emil
Top achievements
Rank 1
Iron
Robert
Top achievements
Rank 1
Want to show your ninja superpower to fellow developers?
Top users last month
Grant
Top achievements
Rank 3
Iron
Iron
Iron
Dean
Top achievements
Rank 1
Leland
Top achievements
Rank 2
Iron
Iron
Iron
Emil
Top achievements
Rank 1
Iron
Robert
Top achievements
Rank 1
Want to show your ninja superpower to fellow developers?
Want to show your ninja superpower to fellow developers?