Telerik Forums
UI for ASP.NET AJAX Forum
6 answers
254 views
Hi all,

I´ve created a web user control (.ascx) which is dynamically added to the page. It contains a RadAjaxPanel which contains a RadGrid, as follows:

<%@ Control Language="C#" AutoEventWireup="true" CodeFile="ComentarioLista.ascx.cs"
    Inherits="Include_RedeSocial20_MuralItem_ComentarioLista" %>
<%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>
<%@ Register Src="../../Investidor/Foto.ascx" TagName="Foto" TagPrefix="uc1" %>
<%@ Register Src="ComentarioItem.ascx" TagName="ComentarioItem" TagPrefix="uc2" %>
<%@ Register Src="../../Mensagem.ascx" TagName="Mensagem" TagPrefix="uc3" %>
<telerik:RadAjaxPanel ID="RadAjaxPanel1" runat="server" HorizontalAlign="NotSet">
    <table style="width: 100%;">
        <tr>
            <td>
                <asp:LinkButton ID="btnComentar" runat="server" OnClick="btnComentar_Click">Comentar</asp:LinkButton>
            </td>
        </tr>
        <tr runat="server" id="trNovoComentario" visible="false">
            <td>
                <asp:TextBox ID="tbComentario" runat="server" MaxLength="2000" TextMode="MultiLine"
                    Width="100%"></asp:TextBox>
                <br />
                <asp:Button ID="btnPostar" runat="server" Text="Postar comentário" CssClass="btnLaranja"
                    OnClick="btnPostar_Click" />
            </td>
        </tr>
        <tr>
            <td>
                <telerik:RadGrid ID="RadGridLista" runat="server" AutoGenerateColumns="False" border="1"
                    GridLines="None" OnItemCreated="RadGridLista_ItemCreated" PageSize="10" SkinID="RadGridForum"
                    OnItemCommand="RadGridLista_ItemCommand">
                    <ClientSettings EnableAlternatingItems="true" EnableRowHoverStyle="false">
                    </ClientSettings>
                    <PagerStyle SEOPagingQueryStringKey="page" />
                    <MasterTableView AllowPaging="true" CellSpacing="-1" NoMasterRecordsText="Nenhum comentário"
                        ShowHeader="False">
                        <RowIndicatorColumn>
                            <HeaderStyle Width="20px" />
                        </RowIndicatorColumn>
                        <ExpandCollapseColumn>
                            <HeaderStyle Width="20px" />
                        </ExpandCollapseColumn>
                        <Columns>
                            <telerik:GridTemplateColumn UniqueName="CODIGO">
                                <ItemTemplate>
                                    <uc2:ComentarioItem ID="ComentarioItem1" runat="server" Codigo='<%#Eval("CODIGO") %>'
                                        DthrInclusao='<%#Eval("DTHR_INCLUSAO") %>' FotoUrl='<%#Eval("FOTO_URL") %>' PublicacaoCodigo='<%#Eval("SLN_PUBL_CODIGO") %>'
                                        Texto='<%#Eval("TEXTO") %>' UsuarioCodigo='<%#Eval("SLN_USUA_CODIGO") %>' UsuarioCodigoPublicacao='<%#Eval("SLN_USUA_CODIGO_AUTOR") %>'
                                        UsuarioNome='<%#Eval("SLN_USUA_NOME") %>' />
                                </ItemTemplate>
                            </telerik:GridTemplateColumn>
                            <telerik:GridTemplateColumn UniqueName="EXCLUIR" HeaderStyle-Width="18px">
                                <ItemTemplate>
                                    <div align="center">
                                        <asp:ImageButton ID="btnExcluir" runat="server" ImageUrl="~/Images/Botao/excluir2.gif"
                                            CommandArgument='<%#Eval("CODIGO") %>' CommandName="Excluir" Visible='<%#GetVisible(Eval("SLN_USUA_CODIGO").ToString(),Eval("SLN_USUA_CODIGO_AUTOR").ToString()) %>' />
                                    </div>
                                </ItemTemplate>
                                <HeaderStyle Width="18px" />
                            </telerik:GridTemplateColumn>
                        </Columns>
                        <PagerStyle Position="Bottom" />
                    </MasterTableView>
                </telerik:RadGrid>
            </td>
        </tr>
    </table>
</telerik:RadAjaxPanel>
<uc3:Mensagem ID="Mensagem1" runat="server" />
<input type="hidden" runat="server" id="tbPublicacaoCodigo" />

And the .CS for this file is as follows:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Telerik.Web.UI;
using System.Data.SqlClient;
  
public partial class Include_RedeSocial20_MuralItem_ComentarioLista : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {
  
    }
  
    public Nullable<decimal> PublicacaoCodigo
    {
        get
        {
            decimal cod;
            bool isCodValido = decimal.TryParse(tbPublicacaoCodigo.Value, out cod);
            if (!isCodValido)
                return null;
            else
                return cod;
        }
        set { tbPublicacaoCodigo.Value = value.ToString(); }
    }
  
    public void BuscaDados()
    {
        UsuarioDataSetTableAdapters.SLN_VW_PUBLICACAO_COMENTARIOTableAdapter ta =
            new UsuarioDataSetTableAdapters.SLN_VW_PUBLICACAO_COMENTARIOTableAdapter();
        UsuarioDataSet.SLN_VW_PUBLICACAO_COMENTARIODataTable dt = new UsuarioDataSet.SLN_VW_PUBLICACAO_COMENTARIODataTable();
  
        dt = ta.GetDataByPublicacao((decimal)PublicacaoCodigo);
        if (dt.Count == 0)
        {
            RadGridLista.Visible = false;
        }
        else
        {
            RadGridLista.Visible = true;
  
            RadGridLista.DataSource = dt;
            RadGridLista.DataBind();
        }
    }
  
    protected bool GetVisible(string usuarioCodigo, string usuarioCodigoPublicacao)
    {
        if ((usuarioCodigoPublicacao.Equals(Sln.Usuario.Usuario.CodigoSessao)) || (usuarioCodigo.Equals(Sln.Usuario.Usuario.CodigoSessao)))
            return true;
        else
            return false;
  
    }
  
    protected void RadGridLista_ItemCreated(object sender, GridItemEventArgs e)
    {
        if (e.Item is GridPagerItem)
        {
            Util.EscondeGridPageSize((GridPagerItem)e.Item);
        }
    }
  
    protected void btnPostar_Click(object sender, EventArgs e)
    {
        SqlTransaction tran = null;
        try
        {
            if (string.IsNullOrEmpty(tbComentario.Text))
            {
                //Page.ClientScript.RegisterStartupScript(Page.GetType(), "aviso", "alert('Comentário não pode ser vazio.');");
                RadAjaxPanel1.ResponseScripts.Add("alert('Comentário não pode ser vazio.');");
                return;
            }
  
            // Pega o código da publicação
            decimal pub = PublicacaoCodigo.Value;
  
            UsuarioDataSetTableAdapters.SLN_PUBLICACAO_COMENTARIOTableAdapter ta = new UsuarioDataSetTableAdapters.SLN_PUBLICACAO_COMENTARIOTableAdapter();
            tran = TableAdapterHelper.BeginTransaction(ta);
  
            decimal cod = (decimal)ta.ProximoCodigo();
  
            ta.Insert(cod, pub, Sln.Usuario.Usuario.CodigoSessao, tbComentario.Text, DateTime.Now);
  
            tran.Commit();
            //Response.Redirect(Request.Url.ToString(), false);
  
            tbComentario.Text = "";
            trNovoComentario.Visible = false;
            BuscaDados();
        }
        catch (Exception ex)
        {
            if (tran != null)
                tran.Rollback();
  
            if (ex.Message.ToLower().IndexOf("a potentially dangerous") >= 0)
                Page.ClientScript.RegisterStartupScript(Page.GetType(), "aviso", "alert('Dangerous text');");
            else
            {
                Log.Insere(string.Format("RedeSocial20.ComentarioLista.Inserir - Usuario: {0} Publicacao: {1} Mensagem: {2} Erro: {3} Trace: {4}",
                    Sln.Usuario.Usuario.CodigoSessao, PublicacaoCodigo, tbComentario.Text, ex.Message, ex.StackTrace), Log.ERROR);
                Mensagem1.Exibe("Desculpe-nos, houve um erro que será analisado por nossa equipe.", false);
            }
        }
        finally
        {
            if (tran != null)
                tran.Dispose();
        }
    }
  
    protected void btnComentar_Click(object sender, EventArgs e)
    {
        if (!trNovoComentario.Visible)
            trNovoComentario.Visible = true;
        else
            trNovoComentario.Visible = false;
    }
  
    protected void RadGridLista_ItemCommand(object source, GridCommandEventArgs e)
    {
        string strCod = e.CommandArgument.ToString();
  
        decimal codigo = decimal.Parse(strCod);
  
        if (e.CommandName.Equals("Excluir"))
        {
            // Efetua exclusão do item e então atualiza lista de comentários
            UsuarioDataSetTableAdapters.SLN_PUBLICACAO_COMENTARIOTableAdapter taCom = new UsuarioDataSetTableAdapters.SLN_PUBLICACAO_COMENTARIOTableAdapter();
            taCom.Delete(codigo);
  
            //RadGridLista.Rebind();
            BuscaDados();
        }
    }
}



Well, the ItemCommand event is not firing, even when "btnExcluir" (the ImageButton) is clicked. What am I doing wrong?

Thanks in advance!
Iana Tsolova
Telerik team
 answered on 01 Nov 2010
5 answers
368 views
I hope this is an easy question to answer.  I have a RadGrid with various bound columns, one of which is a GridDropDownColumn.  I'm binding the column declaritively to a SQLDataSource as follows:

GridDropDownColumn:
<telerik:RadGrid runat="server" ID="rgUserMapping" AutoGenerateColumns="false" AllowPaging="true" PageSize="20">
...
    <%-- MasterTableView Settings --%>
    <MasterTableView AllowSorting="true" Caption="" Summary="" AllowFilteringByColumn="true" ItemStyle-VerticalAlign="Top" DataKeyNames="UserMappingID" CommandItemDisplay="Bottom" EditMode="PopUp">
...
        <%-- Columns --%>
        <Columns>
...
            <telerik:GridDropDownColumn DataField="Component" HeaderText="Component" FilterControlWidth="50" AutoPostBackOnFilter="true" CurrentFilterFunction="Contains" DataSourceID="dsComponentDataSource" ListTextField="Title" ListValueField="ID" DropDownControlType="RadComboBox" />
...
        </Columns>
    </MasterTableView>
</telerik:RadGrid>

When the RadGrid loads, I get what looks like text in the place of the  GridDropDownColumn, and the text is what would be the first item in the bound dropdownlist.

I want the text to read the actual value that comes from the database.  How do I make that happen?
Ryan
Top achievements
Rank 1
 answered on 01 Nov 2010
1 answer
123 views
I'm using the Grid with oData (aka ADO Data Services http://www.telerik.com/help/aspnet-ajax/grdclientbindingtowcfserviceadonetdataservice.html) and am unable to get the grid to scroll with a vertical scrollbar.

How do I make this happen?  It seems that the page size is fixed and won't allow me to render anything outside of a default page boundary.

Also, I'd like to programmaticly navigate to a specific row, on a different page, using javascript. 
Veli
Telerik team
 answered on 01 Nov 2010
2 answers
85 views

Hello All,
 I use an example here: telerik example , I have RadGrid2 with property AllowPaging="true"
In this example, there ia a button and write:"Click PostBack to see the state of the grid is preserved."
And it works well, if I don't  change number of this page,
but if I change the page number all selected values from the preview page  not saved.
I have added to the grid property EnableViewState = "True", but it did not help .

Can you help me please?
Thank you

Oren Kremer
Top achievements
Rank 1
 answered on 01 Nov 2010
2 answers
95 views

Hello All,
 I use an example here: telerik example , I have RadGrid2 with property AllowPaging="true"
In this example, there ia a button and write:"Click PostBack to see the state of the grid is preserved."
And it works well, if I don't  change number of this page,
but if I change the page number all selected values from the preview page  not saved.
I have added to the grid property EnableViewState = "True", but it did not help .

Can you help me please?
Thank you

Oren Kremer
Top achievements
Rank 1
 answered on 01 Nov 2010
4 answers
296 views

Hi,

               I would like to pop up the context menu when an image (Downward arrow in the screenshot) is left clicked in radgrid. Moreover, options in the context menu and its navigate url will vary for each row in grid. How would you implement such scenario? In all your examples, you just have one context menu for all the rows in grid. How do you dynamically populate the context menu based on some radgrid row data?

 

Thanks,

Prashanth

Radoslav
Telerik team
 answered on 01 Nov 2010
3 answers
265 views
I am having an issue with the following 2 ClientSettings on the RadGrid:

EnablePostBackOnRowClick

 and

EnableRowHoverStyle

.
I am using the code to do a LatePanel on the radgrid so that the page loads and then the radgrid can go out and bind the datasource. This is to give the customer the idea that something is actually loading.
This is working great. My problem occurs on initial page load and the 2 settings above are set to true. After the Grid is populated the grid does not respond to clicks nor does the hoverstyle appear on the rows. However if I then click on the hader column to do a sort or use the filter box and then the grid refreshes...both the row clicking and hoverstyle are enabled.

If I remove the latepanel code the grid functions normally meaning it does the row selecting and hoverstyle right at the get go.

The latepanel code is the exact same that is used in various forum queries found here.

Has anyone run into this issue and know of a way to get these to functions to work?

datagrid code:
<telerik:RadAjaxPanel ID="LatePanel" runat="server" width="100%" height="300px" 
                scrollbars="vertical"  >
                <telerik:RadGrid ID="rgOustandingInv" runat="server"
                    OnNeedDataSource="rgOustandingInv_NeedDataSource" EnableViewState="true"
                    OnItemCommand="rgOustandingInv_ItemCommand" AllowFilteringByColumn="True" AllowSorting="True"
                    PageSize="10" AllowPaging="True" EnableNoRecordsTemplate="true">
                      
                    <MasterTableView Width="100%" CommandItemDisplay="Top" CommandItemSettings-ShowAddNewRecordButton="false" CommandItemSettings-ShowRefreshButton="false"
                    AutoGenerateColumns="false" AllowFilteringByColumn="True" TableLayout="Auto" >
                        <PagerStyle Mode="NextPrevNumericAndAdvanced" />
                        <CommandItemSettings ShowExportToWordButton="true" ShowExportToExcelButton="true"
                            ShowExportToCsvButton="true" />
                        <Columns>
                          
                        <telerik:GridBoundColumn FilterControlWidth="105px" DataField="invoiceNo" HeaderText="Invoice No" SortExpression="invoiceNo"
                        UniqueName="invoiceNo" AutoPostBackOnFilter="true" CurrentFilterFunction="Contains" ShowFilterIcon="false"/>
                        <telerik:GridBoundColumn FilterControlWidth="105px" DataField="amount" HeaderText="Amount" SortExpression="amount"
                        UniqueName="amount" AutoPostBackOnFilter="true" CurrentFilterFunction="Contains" ShowFilterIcon="false"/>
                        <telerik:GridBoundColumn FilterControlWidth="105px" DataField="status" HeaderText="Invoice / Payment Status" SortExpression="status"
                        UniqueName="status" AutoPostBackOnFilter="true" CurrentFilterFunction="Contains" ShowFilterIcon="false"/>
                        <telerik:GridDateTimeColumn FilterControlWidth="105px" DataField="schedPayDate" HeaderText="Scheduled Date of Payment" SortExpression="schedPayDate"
                        UniqueName="schedPayDate" AutoPostBackOnFilter="true" CurrentFilterFunction="Contains" ShowFilterIcon="false"/>
                        <telerik:GridBoundColumn FilterControlWidth="105px" DataField="contractId" HeaderText="Contract" SortExpression="contractId"
                        UniqueName="contractId" AutoPostBackOnFilter="true" CurrentFilterFunction="Contains" ShowFilterIcon="false"/>
                        <telerik:GridBoundColumn FilterControlWidth="105px" DataField="contractRelease" HeaderText="contractRelease" SortExpression="contractRelease"
                        UniqueName="contractRelease" AutoPostBackOnFilter="true" CurrentFilterFunction="Contains" ShowFilterIcon="false" Visible="false"/>
                        <telerik:GridBoundColumn FilterControlWidth="105px" DataField="poNo" HeaderText="PO" SortExpression="poNo"
                        UniqueName="poNbr" AutoPostBackOnFilter="true" CurrentFilterFunction="Contains" ShowFilterIcon="false"/>
                        <telerik:GridBoundColumn FilterControlWidth="105px" DataField="poRelease" HeaderText="poRelease" SortExpression="poRelease"
                        UniqueName="poRelease" AutoPostBackOnFilter="true" CurrentFilterFunction="Contains" ShowFilterIcon="false" Visible="false"/>
                        <telerik:GridBoundColumn FilterControlWidth="105px" DataField="poRevision" HeaderText="PO" SortExpression="poRevision"
                        UniqueName="poRevision" AutoPostBackOnFilter="true" CurrentFilterFunction="Contains" ShowFilterIcon="false" Visible="false"/>
  
                        </Columns>
                        <NoRecordsTemplate>
                            <div>There are no records to display</div>
                        </NoRecordsTemplate>
  
                    </MasterTableView>
                    <ClientSettings EnablePostBackOnRowClick="true" EnableRowHoverStyle="true" />
                </telerik:RadGrid>
            </telerik:RadAjaxPanel>

Marin
Telerik team
 answered on 01 Nov 2010
1 answer
96 views
When a users clicks on a row in the datagrid  I need to prompt the user to "OK" or "Cancel" based on certain conditions. If the users select OK I select the row - everything great but if the user selects cancel I cancel the event in the rowselecting event but the current selected row does not stay selected. Any ideas?


Thanks for your help
Som


Marin
Telerik team
 answered on 01 Nov 2010
2 answers
109 views
I have changed the default tooltip of the controls to a Telerik tooltip by adding a RadTooltipManager and set the AutoTooltipify-property to true. This works fine for all controls but the Calendar.
The calendar date tooltips looks good at first showing only the Telerik tooltip. But after changing e.g. the month two tooltips appear when hovering a date - both the default tooltip and the Telerik tooltip.

Any help on how to make only the Telerik tooltip appear would be greatly appreciated!
Jenny
Top achievements
Rank 1
 answered on 01 Nov 2010
1 answer
100 views
I have a RadComboBox within the ItemTemplate of a DetailsView. When using EnableAutomaticLoadOnDemand, all records are initially loaded into the ComboBox. The same ComboBox initially loads no records if I move it outside the DetailsView. Is this a bug with DetailsView? Any known workarounds? I'd rather not use EnableLoadOnDemand and have to code each ComboBox. Code for the offending page is below. There is no code behind for this page.

On edit: looks like updating to the latest version fixed it.
<%@ Page Language="VB" AutoEventWireup="false" %>
 
<%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 
<head id="Head1" runat="server">
    <title>Test</title>
</head>
<body>
    <form id="form1" runat="server">
        <asp:ScriptManager ID="ScriptManager2" runat="server" />
        <asp:DetailsView ID="DetailsView1" runat="server" AutoGenerateRows="False" DataKeyNames="UName" DataSourceID="DetailsViewDataSource">
            <Fields>
                <asp:TemplateField>
                    <ItemTemplate>
                        <telerik:RadComboBox runat="Server" ID="RadComboBox2" EmptyMessage="Select a User" DataSourceID="ComboBoxDataSource" DataValueField="Key" DataTextField="UName" Width="325px" EnableAutomaticLoadOnDemand="true" ItemsPerRequest="10" ShowMoreResultsBox="True" />
                    </ItemTemplate>
                </asp:TemplateField>
            </Fields>
        </asp:DetailsView>
         <asp:SqlDataSource ID="ComboBoxDataSource" runat="server" ConnectionString="<%$ ConnectionStrings:MyConnectionString %>" ProviderName="System.Data.SqlClient" SelectCommand="Select UName, Key From User" >
             </asp:SqlDataSource>
        <asp:SqlDataSource ID="DetailsViewDataSource" runat="server" ConnectionString="<%$ ConnectionStrings:MyConnectionString %>" ProviderName="System.Data.SqlClient" SelectCommand="SELECT UName From User WHERE Key = 1" >
             </asp:SqlDataSource>
    </form>
</body>
</html>
Kalina
Telerik team
 answered on 01 Nov 2010
Narrow your results
Selected tags
Tags
+? more
Top users last month
Jake
Top achievements
Rank 1
RBarnes
Top achievements
Rank 1
Iron
Iron
Rami
Top achievements
Rank 1
Iron
Veteran
Nathan
Top achievements
Rank 1
Kumeri
Top achievements
Rank 1
Iron
Veteran
Iron
Want to show your ninja superpower to fellow developers?
Top users last month
Jake
Top achievements
Rank 1
RBarnes
Top achievements
Rank 1
Iron
Iron
Rami
Top achievements
Rank 1
Iron
Veteran
Nathan
Top achievements
Rank 1
Kumeri
Top achievements
Rank 1
Iron
Veteran
Iron
Want to show your ninja superpower to fellow developers?
Want to show your ninja superpower to fellow developers?