Telerik Forums
UI for ASP.NET AJAX Forum
10 answers
308 views
in the samples of the aps.net ajax controls under listview there is an application scenario called Image Gallery.

I have been trying to reduplicate this application and i am using vb.net. i followed all the tutorials and steps, but when i compile the app i get an error that Photo is not defined

<%@ Import Namespace="Data" %>
<%@ Import Namespace="Photo" %>

Data

Imports System
Imports System.Collections.Generic
Imports System.Drawing.Imaging
Imports System.IO
Imports System.Linq
Imports System.Web
Imports System.Drawing
  
Namespace Data
    Public NotInheritable Class DataProvider
        Private Sub New()
        End Sub
        <ThreadStatic()> _
        Private Shared _photos As List(Of Photo)
  
        Public Shared Function GetData() As IList(Of Photo)
            If _photos IsNot Nothing Then
                Return _photos
            End If
  
            _photos = New List(Of Photo)()
            For Each files As String In Directory.GetFiles(HttpContext.Current.Server.MapPath("~/Images"))
                Dim photo = New Photo() With { _
                    .Name = Path.GetFileName(files) _
                }
  
                Dim image__1 As Image = Image.FromFile(files)
                Using memoryStream = New MemoryStream()
                    image__1.Save(memoryStream, ImageFormat.Png)
                    photo.Data = memoryStream.ToArray()
                End Using
                _photos.Add(photo)
            Next
            Return _photos
        End Function
  
        Public Shared Sub Update(ByVal photoId As Integer, ByVal name As String)
            Dim first As Photo = _photos.FirstOrDefault(Function(p) p.Id = photoId)
  
            If first IsNot Nothing Then
                first.Name = name
            End If
        End Sub
    End Class
  
      
End Namespace

Photo
Public Class Photo
    Private Shared ReadOnly _key As New Object()
    Private Shared _counter As Integer
  
    Public Sub New()
        Id = GetId()
    End Sub
  
    Public Property Name() As String
        Get
            Return m_Name
        End Get
        Set(ByVal value As String)
            m_Name = Value
        End Set
    End Property
    Private m_Name As String
    Public Property Data() As Byte()
        Get
            Return m_Data
        End Get
        Set(ByVal value As Byte())
            m_Data = Value
        End Set
    End Property
    Private m_Data As Byte()
    Public Property Id() As Integer
        Get
            Return m_Id
        End Get
        Private Set(ByVal value As Integer)
            m_Id = Value
        End Set
    End Property
    Private m_Id As Integer
  
    Protected Shared Function GetId() As Integer
        SyncLock _key
            _counter += 1
        End SyncLock
        Return _counter
    End Function
End Class



<ItemTemplate>
                    <fieldset style="float: left; margin: 5px 5px 5px 5px; padding: 2px 2px 2px 2px;
                        background: #eeeeee" class="myClass" onmouseover="containerMouseover(this)" onmouseout="containerMouseout(this)">
                        <telerik:RadBinaryImage Style="cursor: pointer;" runat="server" ID="RadBinaryImage1"
                            DataValue='<%#Eval("Data") %>' Height='<%#ImageHeight %>' Width="<%#ImageWidth %>"
                            ResizeMode="Fit" onclick="<%#CreateWindowScript(DirectCast(Container.DataItem, Photo)) %>"
                            AlternateText="Click to view larger image" ToolTip="Click to view larger image" />
                        <br />
                        <div style="margin-top: -30px; position: fixed; display: none; width: <%#ImageHeight.Value/1.5 %>px;">
                            <asp:TextBox runat="server" ID="TextBox1" Text='<%#Bind("Name") %>' CssClass="txt"
                                OnTextChanged="TextBox1_TextChanged" AutoPostBack="true" ToolTip="Edit image name" />
                        </div>
                    </fieldset>
                </ItemTemplate>


What am i missing here..

Thanks in Advanced

TClemons
Maria Ilieva
Telerik team
 answered on 02 Nov 2011
4 answers
199 views
Hi,

Simple request. I would like to remove the border around the panelbar. It would appear that if I set the BorderWidth="0" does not do it.

Example of what I am trying shown below:-

        <telerik:RadPanelBar ID="RadPanelBar1" runat="server" Skin="Outlook" BorderWidth="0px">  
            <Items> 
                <telerik:RadPanelItem Text="Locations" Expanded="true" BorderWidth="0px">  
                    <ItemTemplate><p>Hello Telerik</p></ItemTemplate>      
                </telerik:RadPanelItem> 
            </Items> 
        </telerik:RadPanelBar> 
 

Is there a Css style I need to override instead?

Thanks,
Martin
Brian Azzi
Top achievements
Rank 2
 answered on 02 Nov 2011
1 answer
82 views
I am probably sure this has been covered somewhere but I cannot find the exact cause of the problem I am experiencing.

I have a grid that has a CommandItemTemplate with an image and Label control.  When the grid is populated with data from a pivot query, the expand column expands to beyond 20 pixels with CommandHeaderDispaly=Top.  When CommandHeaderDisplay=None, I get the correct width as set by the code I have on the page.

Here is the Grid markup:

<telerik:RadGrid ID="rgdFacilityOT" runat="server" Visible="True" Skin="Office2007"
                          oncolumncreated="rgdFacilityOT_ColumnCreated"
                          ondetailtabledatabind="rgdFacilityOT_DetailTableDataBind"
                          onitemdatabound="rgdFacilityOT_ItemDataBound" AutoGenerateColumns="true"
                          onitemcreated="rgdFacilityOT_ItemCreated" MasterTableView-ExpandCollapseColumn-HeaderStyle-Width="20px">
                          <MasterTableView TableLayout="Fixed" CommandItemDisplay="Top">
                          <CommandItemTemplate>
                          <div>
                              <asp:Label runat="server" CssClass="rgHeader" ID="lblFacilityOTGridTitle" Text="" meta:ResourceKey="lblFacilityOTGridTitleResource1"></asp:Label>
                           <div class="export_button_right">
                            <asp:ImageButton ID="btnGridExport" ImageUrl="~/Images/Excel-16x16.gif" OnClick="btnExcel_Click"
                                           runat="server" ToolTip="Export To Excel"
                                   meta:resourcekey="btnGridExportResource1" />
                             </div>
                             </div>
                      </CommandItemTemplate>
                        <CommandItemSettings ShowExportToExcelButton="True"
                            ShowAddNewRecordButton="False" ExportToPdfText="Export to PDF" />
                           <ExpandCollapseColumn Resizable="True" Visible="False">
                         
                        </ExpandCollapseColumn>
                              <CommandItemSettings ExportToPdfText="Export to PDF" />
                        <RowIndicatorColumn Visible="False">
                          
                        </RowIndicatorColumn>

                              <EditFormSettings>
                                  <EditColumn FilterControlAltText="Filter EditCommandColumn column">
                                  </EditColumn>
                              </EditFormSettings>

                          </MasterTableView>
                              <ClientSettings AllowExpandCollapse="False">
                        <Scrolling AllowScroll="True" UseStaticHeaders="False" ScrollHeight="">
                        </Scrolling>
                     </ClientSettings>
                          <FilterMenu EnableImageSprites="False">
                          </FilterMenu>
                          <HeaderContextMenu CssClass="GridContextMenu GridContextMenu_Office2007">
                          </HeaderContextMenu>
               </telerik:RadGrid>   


I just want to be able to control the width of the expand column.  I have tried the following CSS:

.rgExpandCol
{
    width: 10px !important;
       padding-left: 0 !important ;
       padding-right: 0 !important ;
       text-align: left ;
}

but it still does not work. I am sure it is something simple or I have missed something
Pavlina
Telerik team
 answered on 02 Nov 2011
1 answer
88 views
          <telerik:RadGrid AutoGenerateColumns="False" ID="xgrdApprovedAuths" AllowSorting="True"
              OnSortCommand="xgrdApprovedAuths_SortCommand" OnNeedDataSource="xgrdApprovedAuths_NeedDataSource"
              Height="200px" Width="9in" runat="server" CellSpacing="0">
              <ExportSettings ExportOnlyData="true" IgnorePaging="true" OpenInNewWindow="true" />
                  <mastertableview tablelayout="Auto" width="100%" allownaturalsort="false">
                  <Columns>
                      <telerik:GridBoundColumn HeaderText="Status" DataField="ApprovalStatus" UniqueName="ApprovalStatus"
                          SortExpression="ApprovalStatus" HeaderStyle-VerticalAlign="Bottom" HeaderStyle-HorizontalAlign="Center"
                          ShowSortIcon="False" ShowFilterIcon="False" ReadOnly="True" AllowFiltering="False">
                          <HeaderStyle HorizontalAlign="Center" VerticalAlign="Bottom" />
                      </telerik:GridBoundColumn>
                      <telerik:GridBoundColumn HeaderText="AuthID" DataField="AuthID" UniqueName="AuthID"
                          SortExpression="AuthID" Visible="False" HeaderStyle-VerticalAlign="Bottom" ShowSortIcon="False"
                          ShowFilterIcon="False" ReadOnly="True" AllowFiltering="False">
                          <HeaderStyle VerticalAlign="Bottom" />
                      </telerik:GridBoundColumn>
                      <telerik:GridBoundColumn HeaderText="Auth Number" DataField="AuthNumber" UniqueName="AuthNumber"
                          SortExpression="AuthNumber" HeaderStyle-VerticalAlign="Bottom" HeaderStyle-HorizontalAlign="Center"
                          ShowSortIcon="False" ShowFilterIcon="False" ReadOnly="True" AllowFiltering="False">
                          <HeaderStyle HorizontalAlign="Center" VerticalAlign="Bottom" />
                      </telerik:GridBoundColumn>
                      <telerik:GridBoundColumn HeaderText="Auth Adj #" DataField="AuthAmendment" UniqueName="AuthAmendment"
                          SortExpression="AuthAmendment" ItemStyle-Wrap="False" HeaderStyle-VerticalAlign="Bottom"
                          ShowSortIcon="False" ShowFilterIcon="False" ReadOnly="True" AllowFiltering="False"
                          HeaderStyle-HorizontalAlign="Center">
                          <HeaderStyle HorizontalAlign="Center" VerticalAlign="Bottom" />
                          <ItemStyle Wrap="False" />
                      </telerik:GridBoundColumn>
                      <telerik:GridBoundColumn HeaderText="Originator" DataField="CreatedBy" UniqueName="CreatedBy"
                          SortExpression="CreatedBy" ItemStyle-Wrap="False" HeaderStyle-VerticalAlign="Bottom"
                          ShowSortIcon="False" ShowFilterIcon="False" ReadOnly="True" AllowFiltering="False">
                          <HeaderStyle VerticalAlign="Bottom" />
                          <ItemStyle Wrap="False" />
                      </telerik:GridBoundColumn>
                      <telerik:GridBoundColumn HeaderText="MemberID" DataField="MemberID" UniqueName="MemberID"
                          SortExpression="MemberID" Visible="False" HeaderStyle-VerticalAlign="Bottom"
                          ShowSortIcon="False" ShowFilterIcon="False" ReadOnly="True" AllowFiltering="False">
                          <HeaderStyle VerticalAlign="Bottom" />
                      </telerik:GridBoundColumn>
                      <telerik:GridBoundColumn HeaderText="Member Name" DataField="Member Name" UniqueName="Member Name"
                          SortExpression="Member Name" ItemStyle-Wrap="False" HeaderStyle-VerticalAlign="Bottom"
                          ShowSortIcon="False" ShowFilterIcon="False" ReadOnly="True" AllowFiltering="False">
                          <HeaderStyle VerticalAlign="Bottom" />
                          <ItemStyle Wrap="False" />
                      </telerik:GridBoundColumn>
                      <telerik:GridBoundColumn HeaderText="Start Date" DataField="StartDate" UniqueName="StartDate"
                          SortExpression="StartDate" HeaderStyle-VerticalAlign="Bottom" DataType="System.DateTime"
                          ItemStyle-Wrap="False" DataFormatString="{0:MM/dd/yyyy}" ShowSortIcon="False"
                          ShowFilterIcon="False" ReadOnly="True" AllowFiltering="False">
                          <HeaderStyle VerticalAlign="Bottom" />
                          <ItemStyle Wrap="False" />
                      </telerik:GridBoundColumn>
                      <telerik:GridBoundColumn HeaderText="End Date" DataField="EndDate" UniqueName="EndDate"
                          SortExpression="EndDate" HeaderStyle-VerticalAlign="Bottom" DataType="System.DateTime"
                          ItemStyle-Wrap="False" DataFormatString="{0:MM/dd/yyyy}" ShowSortIcon="False"
                          ShowFilterIcon="False" ReadOnly="True" AllowFiltering="False">
                          <HeaderStyle VerticalAlign="Bottom" />
                          <ItemStyle Wrap="False" />
                      </telerik:GridBoundColumn>
                      <telerik:GridBoundColumn HeaderText="Max Units" DataField="MaxUnits" UniqueName="MaxUnits"
                          SortExpression="MaxUnits" HeaderStyle-VerticalAlign="Bottom" ItemStyle-Wrap="False"
                          DataType="System.Int32" DataFormatString="{0:###,##0}" ItemStyle-HorizontalAlign="Right"
                          ShowSortIcon="False" ShowFilterIcon="False" ReadOnly="True" AllowFiltering="False"
                          HeaderStyle-HorizontalAlign="Center">
                          <HeaderStyle HorizontalAlign="Center" VerticalAlign="Bottom" />
                          <ItemStyle HorizontalAlign="Right" Wrap="False" />
                      </telerik:GridBoundColumn>
                      <telerik:GridBoundColumn HeaderText="Units Used" DataField="Units Used" UniqueName="Units Used"
                          SortExpression="Units Used" HeaderStyle-VerticalAlign="Bottom" DataType="System.Int32"
                          ItemStyle-Wrap="False" DataFormatString="{0:###,##0}" ItemStyle-HorizontalAlign="Right"
                          ShowSortIcon="False" ShowFilterIcon="False" ReadOnly="True" AllowFiltering="False"
                          HeaderStyle-HorizontalAlign="Center">
                          <HeaderStyle HorizontalAlign="Center" VerticalAlign="Bottom" />
                          <ItemStyle HorizontalAlign="Right" Wrap="False" />
                      </telerik:GridBoundColumn>
                      <telerik:GridBoundColumn HeaderText="Division" DataField="Division" UniqueName="Division"
                          SortExpression="Division" HeaderStyle-VerticalAlign="Bottom" ItemStyle-Wrap="False"
                          ShowSortIcon="False" ShowFilterIcon="False" ReadOnly="True" AllowFiltering="False"
                          ItemStyle-HorizontalAlign="Center">
                          <HeaderStyle VerticalAlign="Bottom" />
                          <ItemStyle HorizontalAlign="Center" Wrap="False" />
                      </telerik:GridBoundColumn>
                      <telerik:GridBoundColumn HeaderText="Service Description" DataField="Service Description"
                          UniqueName="Service Description" SortExpression="Service Description" AutoPostBackOnFilter="true"
                          CurrentFilterFunction="Contains" HeaderStyle-VerticalAlign="Bottom" ShowSortIcon="False"
                          ShowFilterIcon="False" ReadOnly="True" AllowFiltering="False" ItemStyle-Wrap="False">
                          <HeaderStyle VerticalAlign="Bottom" />
                          <ItemStyle Wrap="False" />
                      </telerik:GridBoundColumn>
                      <telerik:GridBoundColumn HeaderText="Reject Reason" DataField="RejectReason" UniqueName="RejectReason"
                          SortExpression="RejectReason" HeaderStyle-VerticalAlign="Bottom" ItemStyle-Wrap="False"
                          ShowSortIcon="False" ShowFilterIcon="False" ReadOnly="True" AllowFiltering="False">
                          <HeaderStyle VerticalAlign="Bottom" />
                          <ItemStyle Wrap="False" />
                      </telerik:GridBoundColumn>
                  </Columns>
              </mastertableview>
                  <clientsettings>
                  <Scrolling AllowScroll="True" UseStaticHeaders="True" SaveScrollPosition="True">
                  </Scrolling>
              </clientsettings>
          </telerik:RadGrid>
          <asp:Button ID="cmdExport" runat="server" Text="Export to CSV File" OnClick="cmdExport_Click" />
 
  protected void cmdExport_Click(object sender, System.EventArgs e)
  {
      xgrdApprovedAuths.MasterTableView.ExportToExcel();
  }
 
  protected void xgrdApprovedAuths_NeedDataSource(object source, GridNeedDataSourceEventArgs e)
  {
      try
      {
        clsAuthorizations auth = new clsAuthorizations(ss.dbConnect);
 
          DateTime FromDate;
          DateTime ToDate;
 
          if (txtProcessedStartDate.SelectedDate == null)
          {
              FromDate = System.DateTime.Now.AddYears(-50);
          }
          else
          {
              FromDate = txtProcessedStartDate.SelectedDate.Value;
          }
 
          if (txtProcessedEndDate.SelectedDate == null)
          {
              ToDate = System.DateTime.Now.AddYears(50);
          }
          else
          {
              ToDate = txtProcessedEndDate.SelectedDate.Value;
          }
 
          int ProviderID = ss.ProviderID;
 
          this.xgrdApprovedAuths.DataSource = auth.GetViewOnlyApprovedAuths(ProviderID, FromDate, ToDate, cboProcessedStatus.SelectedItem.Text, cboProcessedDivision.SelectedItem.Text, ss.listDivisionString);
          //this.xgrdApprovedAuths.DataBind();
 
   this.updApprovedAuths.Update();
}
   catch (Exception ex)
      {
          clsPortalErrorLog err = new clsPortalErrorLog(ss.dbConnect);
          err.LogError(ex.ToString(), User.Identity.Name, "AuthsMain.aspx", "BindApprovedAuths");
      }
  }
Using the following code I get error in the ScriptResource tab showing your java script.


I'm using Telerek version Q1 2011 with Visual Studio 2008.

I'm trying to export the grid to Excel.

 

Mira
Telerik team
 answered on 02 Nov 2011
5 answers
817 views
I am suddenly getting the following error message:
DataBinding: 'System.Data.DataRowView' does not contain a property with the name '16'.

The grid is used for a timesheet application, and has 16 date columns.  The 16th column is added for months with 31 days.  For the first 15 days of the month, only columns 1-15 are shown, and column 16 is hidden.  The logic for hiding the column is simple; if the data contains the key word "hide" in the columns display field, it sets the columns visible property to false.  This should prevent the binding of the column from happening.  In fact, it has been working in production since January 1st, 2009.  However, after adding a column to the grid, this logic no longer works.  I reference all columns by unique name, not column number, so the addition of a column should not have changed the existing functionality.

Here is the column's definition:
<telerik:GridTemplateColumn DataField="16" HeaderStyle-Font-Size="8pt" FooterStyle-Font-Bold="true" 
    HeaderStyle-HorizontalAlign="Center" HeaderText="16" ItemStyle-HorizontalAlign="Center" SortExpression="16" UniqueName="16" 
    Visible="true">
    <ItemTemplate>
        <%# Eval("16")%>
    </ItemTemplate>
    <EditItemTemplate>
        <telerik:RadNumericTextBox ID="txt16" runat="server" MaxValue="24" MinValue="0" 
            NumberFormat-DecimalDigits="1" TabIndex="90" Text='<%# Bind("16") %>' 
            Width="20px" />
    </EditItemTemplate>
    <FooterStyle Font-Bold="True" HorizontalAlign="Center" VerticalAlign="Middle" 
        Width="26px" />
    <HeaderStyle Font-Size="8pt" HorizontalAlign="Center" VerticalAlign="Middle" 
        Width="26px" />
    <ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" Width="26px" />
</telerik:GridTemplateColumn>

Here is the code that hides the column:
//Hide date columns that are needed for this reporting period (14 day and 15 day reporting periods)
if (dateheaderdisplaytext == "hide")
{
    //hide the columns that are not in this reporting date range.
    RadGrid1.MasterTableView.GetColumn(sequence).Visible = false;
}
else
{
    header[sequence].Text = dateheaderdisplaytext;
}

I have verified that the columns dateheaderdisplaytext is set to hide for column 16 (see attachment), and have also verified through Team Foundation Server that no code related to column 16 or the logic to hide the column has changed.  Additionally, I have verified that the Telerik control version is the same in production (where it is working) as on my development machine (where it is not working).  The version is 2010.3.1317.40. 

Please advise me as to what could have gone wrong.

Thanks,
Nathan
Iana Tsolova
Telerik team
 answered on 02 Nov 2011
1 answer
110 views

Using VS 2008 SP1 with RadControls for ASP.NET 2011.2.712.V 2.

 

I copied below example into my Project.

 

http://demos.telerik.com/aspnet-ajax/grid/examples/programming/filteringtemplatecolumns/defaultcs.aspx

 

After adding the FilteringTemplateColumns.cs in APP_Code folder, I am getting attached error message.

The results are OK except the error shows in Visual Studio Design/Split Mode. This error does not
show in Telerik Demo.


Below is complete Code:

<%@ Page Language="c#" AutoEventWireup="false" CodeFile="DefaultCS.aspx.cs" Inherits="Telerik.GridExamplesCSharp.Programming.FilteringTemplateColumns.DefaultCS" %>
  
<%@ Register TagPrefix="custom" Namespace="FilteringTemplateColumns" %>
<%@ Register TagPrefix="telerik" Namespace="Telerik.Web.UI" Assembly="Telerik.Web.UI" %>
  
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
<head runat="server">
     
</head>
<body >
    <form id="mainForm" method="post" runat="server">
          
     <telerik:RadScriptManager ID="RadScriptManager1" runat="server" />
         
        <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">
            <AjaxSettings>
                <telerik:AjaxSetting AjaxControlID="RadGrid1">
                    <UpdatedControls>
                        <telerik:AjaxUpdatedControl ControlID="RadGrid1" />
                    </UpdatedControls>
                </telerik:AjaxSetting>
            </AjaxSettings>
        </telerik:RadAjaxManager>
        <telerik:RadGrid ID="RadGrid1" DataSourceID="SqlDataSource1" Width="97%" AllowFilteringByColumn="True"
            AllowSorting="True" PageSize="12" ShowFooter="True" AllowPaging="True" runat="server"
            AutoGenerateColumns="False" GridLines="None" ShowStatusBar="true">
              <GroupingSettings CaseSensitive="false" />
            <MasterTableView EditMode="InPlace" AllowFilteringByColumn="True" ShowFooter="True"
                DataKeyNames="CustomerID" TableLayout="Auto">
                <Columns>
                    <telerik:GridBoundColumn DataField="ContactName" HeaderText="Contact name">
                        <HeaderStyle Width="25%" />
                    </telerik:GridBoundColumn>
                    <telerik:GridBoundColumn DataField="ContactTitle" HeaderText="Contact title"
                     AutoPostBackOnFilter="true" CurrentFilterFunction="Contains" ShowFilterIcon="false">
                        <HeaderStyle Width="25%" />
                    </telerik:GridBoundColumn>
                    <telerik:GridTemplateColumn DataField="City" HeaderText="TemplateColumn City">
                        <HeaderStyle Width="25%" />
                        <ItemTemplate>
                            <%# Eval("City") %>
                        </ItemTemplate>
                    </telerik:GridTemplateColumn>
                   <custom:MyCustomFilteringColumn DataField="Country" FilterControlWidth="180px" 
                   HeaderText="Custom TemplateColumn Country">
                        <headerstyle width="25%" />
                        <itemtemplate>
                              <img src='Img/<%# Eval("Country") %>.gif'
                               alt="" style="vertical-align:middle;margin-right:7px;"/><%# Eval("Country") %>
                        </itemtemplate>
                    </custom:MyCustomFilteringColumn>
                </Columns>
            </MasterTableView>
        </telerik:RadGrid>
        <br />
        <asp:SqlDataSource ID="SqlDataSource1" ConnectionString="<%$ ConnectionStrings:NorthWindConnectionString %>"
            ProviderName="System.Data.SqlClient" SelectCommand="SELECT CustomerID, ContactName, ContactTitle, Country, City FROM Customers"
            runat="server"></asp:SqlDataSource>
  
      
        
    </form>
</body>
</html>
  
DefaultCS.aspx.cs
_____________
  
  
using Telerik.Web.UI;
using System.Web.UI.WebControls;
  
namespace Telerik.GridExamplesCSharp.Programming.FilteringTemplateColumns
{
    public partial class DefaultCS : System.Web.UI.Page
    {
    }
  
}
_________
  
FilteringTemplateColumns.cs
  
using Telerik.Web.UI;
using System.Data;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Configuration;
  
  
namespace FilteringTemplateColumns
{
    public class MyCustomFilteringColumn : GridTemplateColumn
    {
  
        public DataTable GetDataTable(string queryString)
        {
            string ConnString = ConfigurationManager.ConnectionStrings["NorthWindConnectionString"].ConnectionString;
            SqlConnection MySqlConnection = new SqlConnection(ConnString);
            SqlDataAdapter MySqlDataAdapter = new SqlDataAdapter();
            MySqlDataAdapter.SelectCommand = new SqlCommand(queryString, MySqlConnection);
  
            DataTable myDataTable = new DataTable();
            MySqlConnection.Open();
            try
            {
                MySqlDataAdapter.Fill(myDataTable);
            }
            finally
            {
                MySqlConnection.Close();
            }
  
            return myDataTable;
        }
  
        protected override void SetupFilterControls(TableCell cell)
        {
            RadComboBox rcBox = new RadComboBox();
            rcBox.ID = "DropDownList1";
            //rcBox.Width = Unit.Percentage(100);
            rcBox.AutoPostBack = true;
            rcBox.DataTextField = this.DataField;
            rcBox.DataValueField = this.DataField;
            rcBox.SelectedIndexChanged += rcBox_SelectedIndexChanged;
            DataTable table = GetDataTable(string.Format("SELECT DISTINCT {0} FROM {1}", this.DataField, "Customers"));
            DataRow row = table.NewRow();
            row[this.DataField] = "";
            table.Rows.InsertAt(row, 0);
            rcBox.DataSource = table;
            cell.Controls.Add(rcBox);
        }
  
        protected override void SetCurrentFilterValueToControl(TableCell cell)
        {
            if (!(this.CurrentFilterValue == ""))
            {
                ((RadComboBox)cell.Controls[0]).Items.FindItemByText(this.CurrentFilterValue).Selected = true;
            }
        }
  
        protected override string GetCurrentFilterValueFromControl(TableCell cell)
        {
            string currentValue = ((RadComboBox)cell.Controls[0]).SelectedItem.Value;
            this.CurrentFilterFunction = (currentValue != "")? GridKnownFunction.EqualTo : GridKnownFunction.NoFilter;
            return currentValue;
        }
  
        private void rcBox_SelectedIndexChanged(object sender, Telerik.Web.UI.RadComboBoxSelectedIndexChangedEventArgs e)
        {
            ((GridFilteringItem)(((RadComboBox)sender).Parent.Parent)).FireCommandEvent("Filter", new Pair());
        }
    }
}

Any help will be appreciated.

 

Thanks


GC_0620


Andrey
Telerik team
 answered on 02 Nov 2011
4 answers
143 views
Hi,

I've got a problem with the ClientEvents-OnFocus of RadTextBox.
The scenario is: 
In the RadTextBox I've a text with a ForeColor, when the user click in the textbox (ClientEvents OnFocus) a javascript function delete the text and change the ForeColor of the textbox, but when I test the page the browser notify me that there's an error in the page. The error is with the registration of the js call on the page:
 

<

 

 

telerik:RadTextBox ID="txtComuneBene" runat="server" Width="350px" AutoPostBack="true" ClientEvents-OnFocus="javascript:setControlFocus('txtComuneBene');">

 

 

 

</telerik:RadTextBox>
I also tried with :

 

<telerik:RadTextBox ID="txtComuneBene" runat="server" Width="350px" ClientEvents-OnFocus="javascript:setControlFocus('txtComuneBene');">

 

 

 

</telerik:RadTextBox>
and

 

<telerik:RadTextBox ID="txtComuneBene" runat="server" Width="350px" ClientEvents-OnFocus="setControlFocus('txtComuneBene');">

 

 

 

 

 

 

 

</telerik:RadTextBox>

and

<telerik:RadTextBox ID="txtComuneBene" runat="server" Width="350px" ClientEvents-OnFocus="setControlFocus('txtComuneBene')">

 

 

 

 

 

 

 

</telerik:RadTextBox>

 

 

 

and finally I try with a js alert to test if I write something wrong but the result is always the same.

<telerik:RadTextBox ID="txtComuneBene" runat="server" Width="350px" ClientEvents-OnFocus="alert('test alert');">

 

 

 

</telerik:RadTextBox>

 
a js error with this message :
Message: Expected '}'

And this is the ajax registration ( the problem is the italic style text):
Sys.Application.add_init(

 

function() {

 

$create(Telerik.Web.UI.RadTextBox, {

 

"_focused":false,"_postBackEventReferenceScript":"setTimeout(\"__doPostBack(\\\u0027ctl00$MainContent$ucRichiestaServizio$txtComuneBene\\\u0027,\\\u0027\\\u0027)\", 0)","_skin":"Default","clientStateFieldID":"ctl00_MainContent_ucRichiestaServizio_txtComuneBene_ClientState","enabled":true,"styles":{HoveredStyle: ["width:350px;", "riTextBox riHover"],InvalidStyle: ["width:350px;", "riTextBox riError"],DisabledStyle: ["width:350px;", "riTextBox riDisabled"],FocusedStyle: ["width:350px;", "riTextBox riFocused"],EmptyMessageStyle: ["width:350px;", "riTextBox riEmpty"],ReadOnlyStyle: ["width:350px;", "riTextBox riRead"],EnabledStyle: ["width:350px;", "riTextBox riEnabled"]}}, {"focus":javascript:setControlFocus('txtComuneBene');}, null, $get("ctl00_MainContent_ucRichiestaServizio_txtComuneBene"));

 

});



any ideas?

another question :

I've got a page with a RadWindowManager that shows a confirm window, if I click on the "Ok" button the page is refreshed with a complete postback, is there a way to avoid this complete postback? I register in the RadAjaxManager that the RadWindowManager has to refresh a panel inside the page with the RadAjaxLoadingPanel that I have in the page.

thanks in advance,
regards
Alessandro
Alessandro
Top achievements
Rank 1
 answered on 02 Nov 2011
5 answers
287 views
Hello Telerik team,

I am having a grid with few columns bound to it. I have set datasource for grid in code behind. Also i want to insert/update & delete in code behind.
Please refer the .aspx & .aspx.cs code page below.
ASPX Page.
<telerik:RadGrid ID="Grid_products" AllowPaging="true" PageSize="25" Skin="Vista" runat="server"  
            OnNeedDataSource="Grid_products_NeedDataSource" Width="100%" AutoGenerateColumns="false" HorizontalAlign="NotSet"  
            OnUpdateCommand="Grid_products_UpdateCommand" OnInsertCommand="Grid_products_InsertCommand" OnDeleteCommand="Grid_products_DeleteCommand"
                
                <PagerStyle Mode="NextPrevAndNumeric" /> 
                
                <MasterTableView Width="100%" CommandItemDisplay="Top" DataKeyNames="ProductID" EditMode ="InPlace"
                
                <Columns> 
                
                <telerik:GridEditCommandColumn ButtonType="ImageButton" HeaderText="Edit" UniqueName="EditCommandColumn"
                        <ItemStyle CssClass="MyImageButton" /> 
                    </telerik:GridEditCommandColumn> 
                
                    <telerik:GridBoundColumn UniqueName="ProductName" HeaderText="Product Name" DataField="ProductName" ColumnEditorID = "Grid_ProductsTextBox_ProductName"
                    </telerik:GridBoundColumn> 
                     
                     
                     
                     
                    <telerik:GridBoundColumn UniqueName="RetailPrice" HeaderText="Retail Price" DataField="RetailPrice" ColumnEditorID = "Grid_ProductsTextBox_RetailPrice"
                    </telerik:GridBoundColumn> 
                     
                    <telerik:GridBoundColumn UniqueName="WholesalePrice" HeaderText="WholesalePrice Name" DataField="WholesalePrice" ColumnEditorID = "Grid_ProductsTextBox_WholesalePrice"
                    </telerik:GridBoundColumn> 
                     
                    <telerik:GridBoundColumn UniqueName="CustomerPrice" HeaderText="CustomerPrice Name" DataField="CustomerPrice" ColumnEditorID = "Grid_ProductsTextBox_CustomerPrice"
                    </telerik:GridBoundColumn> 
                     
                    <telerik:GridBoundColumn UniqueName="Description" HeaderText="Description" DataField="Description" ColumnEditorID = "Grid_ProductsTextBox_Description"
                    </telerik:GridBoundColumn> 
                     
                    <telerik:GridBoundColumn UniqueName="UsageTime" HeaderText="Usage Time" DataField="UsageTime" ColumnEditorID = "Grid_ProductsTextBox_UsageTime"
                    </telerik:GridBoundColumn> 
                     
                    <telerik:GridBoundColumn UniqueName="FollowupTime" HeaderText="Followup Time" DataField="FollowupTime" ColumnEditorID = "Grid_ProductsTextBox_FollowupTime"
                    </telerik:GridBoundColumn> 
                     
                    <telerik:GridBoundColumn UniqueName="ReminderTime" HeaderText="Reminder Time" DataField="ReminderTime" ColumnEditorID = "Grid_ProductsTextBox_ReminderTime"
                    </telerik:GridBoundColumn> 
                     
                     
                     
                
                    <telerik:GridButtonColumn HeaderText="Delete" ConfirmText="Delete this product?" ConfirmDialogType="RadWindow" 
                    ConfirmTitle="Delete" ButtonType="ImageButton" CommandName="Delete" Text="Delete" 
                    UniqueName="DeleteColumn"
                
                    <ItemStyle HorizontalAlign="Center" CssClass="MyImageButton" /> 
                
                </telerik:GridButtonColumn> 
                 
                </Columns> 
                 
                <ExpandCollapseColumn Visible="False"
                    <HeaderStyle Width="10px" /> 
                </ExpandCollapseColumn> 
                 
                <RowIndicatorColumn Visible="False"
                    <HeaderStyle Width="20px" /> 
                </RowIndicatorColumn> 
                 
                </MasterTableView> 
                <ClientSettings> 
                    <ClientEvents OnRowDblClick="RowDblClick" OnGridCreated="GridCreated" 
                        OnCommand="GridCommand" /> 
                </ClientSettings> 
            </telerik:RadGrid> 
            <telerik:GridTextBoxColumnEditor ID="Grid_ProductsTextBox_ProductName"  
                runat="server"/> 
                <telerik:GridTextBoxColumnEditor ID="Grid_ProductsTextBox_Description"  
                runat="server"/> 
                
               <telerik:GridNumericColumnEditor ID="Grid_ProductsTextBox_RetailPrice" runat="server"
               <NumericTextBox ID="NumericTextBox1" runat="server" Type="Number"
               <NumberFormat KeepNotRoundedValue="false" AllowRounding="true" DecimalDigits="2" /> 
               </NumericTextBox> 
               </telerik:GridNumericColumnEditor> 
               <telerik:GridNumericColumnEditor ID="Grid_ProductsTextBox_WholesalePrice" runat="server"
               <NumericTextBox ID="NumericTextBox2" runat="server" Type="Number"
               <NumberFormat KeepNotRoundedValue="false" AllowRounding="true" DecimalDigits="2" /> 
               </NumericTextBox> 
               </telerik:GridNumericColumnEditor> 
               <telerik:GridNumericColumnEditor ID="Grid_ProductsTextBox_CustomerPrice" runat="server"
               <NumericTextBox runat="server" Type="Number"
               <NumberFormat KeepNotRoundedValue="false" AllowRounding="true" DecimalDigits="2" /> 
               </NumericTextBox> 
               </telerik:GridNumericColumnEditor> 
                
               <telerik:GridNumericColumnEditor ID="Grid_ProductsTextBox_UsageTime" runat="server"
               <NumericTextBox ID="NumericTextBox3" runat="server" Type="Number"
               <NumberFormat KeepNotRoundedValue="true" AllowRounding="false"/> 
               </NumericTextBox> 
               </telerik:GridNumericColumnEditor> 
               <telerik:GridNumericColumnEditor ID="Grid_ProductsTextBox_FollowupTime" runat="server"
               <NumericTextBox ID="NumericTextBox4" runat="server" Type="Number"
               <NumberFormat KeepNotRoundedValue="true" AllowRounding="false"/> 
               </NumericTextBox> 
               </telerik:GridNumericColumnEditor> 
               <telerik:GridNumericColumnEditor ID="Grid_ProductsTextBox_ReminderTime" runat="server"
               <NumericTextBox ID="NumericTextBox5" runat="server" Type="Number"
               <NumberFormat KeepNotRoundedValue="true" AllowRounding="false"/> 
               </NumericTextBox> 
               </telerik:GridNumericColumnEditor> 


ASPX.CS page

 #region Products Grid 
 
    protected void Grid_products_NeedDataSource(object source, GridNeedDataSourceEventArgs e) 
    { 
        Grid_products.DataSource = GetDataTable(); 
    } 
    //string connectionString = WebConfigurationManager.ConnectionStrings["SchedulerConnectionString"].ConnectionString; 
    private DataTable GetDataTable() 
    { 
        DataTable datatable; 
        if (txt_productsearch.Text.Trim() != ""
        { 
            string selectSQL = "SELECT [ProductID], [ProductName], [RetailPrice], [WholesalePrice], [CustomerPrice], [Description],[UsageTime],[FollowupTime],[ReminderTime] FROM [Products] where ProductName LIKE '%" + txt_productsearch.Text + "%'  and AdminID =1"
            //string selectSQL = "SELECT ProductID,ProductName FROM [Products] Where ProductName LIKE '%" + txt_productsearch.Text + "%'  and AdminID =1"; 
            SqlConnection con = new SqlConnection(connectionString); 
            SqlCommand cmd = new SqlCommand(selectSQL, con); 
            //SqlDataReader reader; 
            SqlDataAdapter da = new SqlDataAdapter(selectSQL, connectionString); 
            datatable = new DataTable(); 
            //da.Fill(datatable); 
 
            //OleDbConnection connection1 = new OleDbConnection(); 
            //OleDbDataAdapter adapter1 = new OleDbDataAdapter(); 
            //adapter1.SelectCommand = new OleDbCommand(query, connection1); 
            //DataTable table1 = new DataTable(); 
            //connection1.Open(); 
            try 
            { 
                //adapter1.Fill(table1); 
                da.Fill(datatable); 
            } 
            finally 
            { 
                //connection1.Close(); 
            } 
 
        } 
        else 
        { 
            string selectSQL = "SELECT [ProductID], [ProductName], [RetailPrice], [WholesalePrice], [CustomerPrice], [Description],[UsageTime],[FollowupTime],[ReminderTime] FROM [Products] Where ProductName= ' ' and AdminID =1"
            SqlConnection con = new SqlConnection(connectionString); 
            SqlCommand cmd = new SqlCommand(selectSQL, con); 
            //SqlDataReader reader; 
            SqlDataAdapter da = new SqlDataAdapter(selectSQL, connectionString); 
            datatable = new DataTable(); 
            da.Fill(datatable); 
 
        } 
        return datatable; 
    } 
    protected void RadAjaxManager1_AjaxRequest(object sender, Telerik.Web.UI.AjaxRequestEventArgs e) 
    { 
        if (e.Argument.IndexOf("FilterGrid") != -1) 
        { 
            Grid_products.Rebind(); 
        } 
    } 
    protected void Grid_products_InsertCommand(object source, GridCommandEventArgs e) 
    { 
        GridEditableItem editedItem = e.Item as GridEditableItem; 
        //(editedItem.EditManager.GetColumnEditor("") as GridNumericColumnEditor). 
        //GridTextBoxColumnEditor itemupdate = e.Item.DataItem as GridTextBoxColumnEditor; 
        //Get the primary key value using the DataKeyValue. 
        //int ProductID = Convert.ToInt32(editedItem.OwnerTableView.DataKeyValues[editedItem.ItemIndex]["ProductID"].ToString()); 
        string ProductName = (editedItem.EditManager.GetColumnEditor("ProductName"as GridTextBoxColumnEditor).Text; 
        string RetailPrice = (editedItem.EditManager.GetColumnEditor("RetailPrice"as GridNumericColumnEditor).Text; 
        string WholesalePrice = (editedItem.EditManager.GetColumnEditor("WholesalePrice"as GridNumericColumnEditor).Text; 
        string CustomerPrice = (editedItem.EditManager.GetColumnEditor("CustomerPrice"as GridNumericColumnEditor).Text; 
        string Description = (editedItem.EditManager.GetColumnEditor("Description"as GridTextBoxColumnEditor).Text; 
        string UsageTime = (editedItem.EditManager.GetColumnEditor("UsageTime"as GridNumericColumnEditor).Text; 
        string FollowupTime = (editedItem.EditManager.GetColumnEditor("FollowupTime"as GridNumericColumnEditor).Text; 
        string ReminderTime = (editedItem.EditManager.GetColumnEditor("ReminderTime"as GridNumericColumnEditor).Text; 
        //string RetailPrice = (editedItem.EditManager.GetColumnEditor("RetailPrice") as GridNumericColumnEditor).Text; 
         
        //string FirstName = (itemupdate.FindControl("Grid_contactsTextBox_FirstName") as GridTextBoxColumnEditor).Text; 
        string InsertSQL = "Insert into Products(ProductName,RetailPrice,WholesalePrice,CustomerPrice,Description,UsageTime,FollowupTime,ReminderTime,AdminID) Values('" + ProductName +","+ Convert.ToInt32(RetailPrice) + "," + Convert.ToInt32(WholesalePrice) + "," + Convert.ToInt32(CustomerPrice) + "," + Description + "," + Convert.ToInt32(UsageTime) + "," + Convert.ToInt32(FollowupTime) + "," + Convert.ToInt32(ReminderTime) + "',1)"
        SqlConnection con = new SqlConnection(connectionString); 
        SqlCommand cmd = new SqlCommand(InsertSQL, con); 
        int flag; 
        try 
        { 
            con.Open(); 
            flag = cmd.ExecuteNonQuery(); 
        } 
        catch (Exception Error) 
        { 
 
        } 
        finally 
        { 
            con.Close(); 
        } 
 
    } 
    protected void Grid_products_DeleteCommand(object source, GridCommandEventArgs e) 
    { 
 
    } 
    protected void Grid_products_UpdateCommand(object source, GridCommandEventArgs e) 
    { 
        GridEditableItem editedItem = e.Item as GridEditableItem; 
        //GridTextBoxColumnEditor itemupdate = e.Item.DataItem as GridTextBoxColumnEditor; 
        //Get the primary key value using the DataKeyValue. 
        int ProductID = Convert.ToInt32(editedItem.OwnerTableView.DataKeyValues[editedItem.ItemIndex]["ProductID"].ToString()); 
        string ProductName = (editedItem.EditManager.GetColumnEditor("ProductName"as GridTextBoxColumnEditor).Text; 
        //string FirstName = (itemupdate.FindControl("Grid_contactsTextBox_FirstName") as GridTextBoxColumnEditor).Text; 
        string UpdateSQL = "Update Products set ProductName='" + ProductName + "' where ProductID =" + ProductID + "  where AdminID =1"
        SqlConnection con = new SqlConnection(connectionString); 
        SqlCommand cmd = new SqlCommand(UpdateSQL, con); 
        int flag; 
        try 
        { 
            con.Open(); 
            flag = cmd.ExecuteNonQuery(); 
        } 
        catch (Exception Error) 
        { 
 
        } 
        finally 
        { 
            con.Close(); 
        } 
    } 
    #endregion 



My problem is that:
1)  I am not able to insert any new record. when i click on add new record it goes to "Grid_products_InsertCommand" event. There it takes the value of "ProductName" but when it try to execute for getting "RetailPrice" it throws an exception "Object reference not set to an instance of an object.". Its just taking "ProductName" and for rest of them its showing the same exception. I dont know what the problem is with it.

2) I am not able to validate these text boxes used in grid for insert/update. There are 2 types of GridColumnEditor that i hav used. they are
a) Textbox.
b) Numeric.
It would be helpful if i could have a sample application that validates both.
Please help me as soon as possible.
Its kind of very urgent.


Thank You,
Chinmay Sharma.
Sebastian
Telerik team
 answered on 02 Nov 2011
3 answers
180 views
Hello smart minds of the Telerik forums,

I'm trying to put together something like a "timeline" graph which shows phases of a project versus the actual dates certain items occurred. What I was thinking was:

1) A horizontal stacked bar graph (which could indicate the phases)
2) Point-type dots along the graph that would indicate the individual dates that things occurred.

Anyone have a better idea? I haven't tried to flesh it out yet, but I will shortly. Just wanted to see if anyone had tried something like this before and had issues? or am I going about it the completely wrong way?

Thanks! 
Kori
Ves
Telerik team
 answered on 02 Nov 2011
1 answer
136 views
Hi

I cant find the reason why the chart display's X (no image) on the server but works fine on my localhost : view attachements.

Yes in is registered in the web.config for IIS 6 and 7

I have full trust : <trust level="Full" />

I have just added 2 new images calling the file directly with the url

Thanks

Mike
Ves
Telerik team
 answered on 02 Nov 2011
Narrow your results
Selected tags
Tags
+? more
Top users last month
Edmond
Top achievements
Rank 1
Iron
fabrizio
Top achievements
Rank 2
Iron
Veteran
RobMarz
Top achievements
Rank 2
Iron
Fakhrul
Top achievements
Rank 1
Iron
Tejas
Top achievements
Rank 2
Iron
Iron
Iron
Want to show your ninja superpower to fellow developers?
Top users last month
Edmond
Top achievements
Rank 1
Iron
fabrizio
Top achievements
Rank 2
Iron
Veteran
RobMarz
Top achievements
Rank 2
Iron
Fakhrul
Top achievements
Rank 1
Iron
Tejas
Top achievements
Rank 2
Iron
Iron
Iron
Want to show your ninja superpower to fellow developers?
Want to show your ninja superpower to fellow developers?