RSS

Monthly Archives: January 2012

How to disable previous date in Rad Date Picker


if you want to disable the Previous date selection, you may use SelectableDateStart property of RadDatePicker.
Here is a sample code:

txtStartDate.SelectableDateStart = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day);
txtEndDate.SelectableDateStart = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day);

Or

// txtStartDate.SelectableDateStart = DateTime.Today;

//txtEndDate.SelectableDateStart = DateTime.Today;

Advertisements
 
Leave a comment

Posted by on January 31, 2012 in Silverlight

 

Tags: , , ,

Maintaining cell state in the Telerik RadGridView for Silverlight


Hi Dear

if you want to click on one empty row cell then enable that row cell button enable then this post help you.

Another help this post you if you want to load save,edit button first load disable if specific column cell empty or value then you apply this code.

 

Design Side Code

Interactivity which is dll

<UserControl x:Class=”SetMyLeads.Silverlight.UI.Controls.CallFowerdGrid”
xmlns:telerik=”http://schemas.telerik.com/2008/xaml/presentation&#8221;
xmlns=”http://schemas.microsoft.com/winfx/2006/xaml/presentation&#8221;
xmlns:x=”http://schemas.microsoft.com/winfx/2006/xaml&#8221;
xmlns:d=”http://schemas.microsoft.com/expression/blend/2008&#8243;
xmlns:mc=”http://schemas.openxmlformats.org/markup-compatibility/2006&#8243;
xmlns:local=”clr-namespace:SetMyLeads.Silverlight.UI”

xmlns:i=”clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity”
mc:Ignorable=”d”>

<Grid x:Name=”LayoutRoot” Background=”White” MinWidth=”800″ MinHeight=”500″ MaxHeight=”500″>
<Grid.ColumnDefinitions>
<ColumnDefinition Width=”*” />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height=”*” />
<RowDefinition Height=”25″></RowDefinition>
</Grid.RowDefinitions>

<telerik:RadGridView x:Name=”rgdCallForwerding” Grid.Row=”0″ Grid.Column=”0″ AutoGenerateColumns=”False”  Style=”{StaticResource DefaultGridStyle}” ScrollViewer.VerticalScrollBarVisibility=”Auto”   RowIndicatorVisibility=”Collapsed” SelectionChanged=”rgdCallForwerding_SelectionChanged” RowEditEnded=”rgdCallForwerding_RowEditEnded” RowLoaded=”rgdCallForwerding_RowLoaded”>
<telerik:RadGridView.Columns>
<telerik:GridViewDataColumn DataMemberBinding=”{Binding CompanyName}” Header=”CompanyName” Width=”auto” IsReadOnly=”True” />
<telerik:GridViewDataColumn DataMemberBinding=”{Binding Number}” Header=”Company Number” Width=”auto” IsReadOnly=”True”/>
<telerik:GridViewDataColumn Header=”FowardNumber”
DataMemberBinding=”{Binding FowardNumber, Mode=TwoWay}” Width=”auto”>
<telerik:GridViewDataColumn.CellTemplate>
<DataTemplate>
<TextBlock Text=”{Binding FowardNumber}” />
</DataTemplate>
</telerik:GridViewDataColumn.CellTemplate>
<telerik:GridViewDataColumn.CellEditTemplate>
<DataTemplate>
<TextBox Text=”{Binding FowardNumber, Mode=TwoWay}”  x:Name=”txtFowardNumber” />

</DataTemplate>
</telerik:GridViewDataColumn.CellEditTemplate>
</telerik:GridViewDataColumn>

<telerik:GridViewColumn Width=”100″>
<telerik:GridViewColumn.CellTemplate>
<DataTemplate>
<telerik:RadButton x:Name=”btnSave”  ToolTipService.ToolTip=”Save Company Fowarding Number” Command=”{Binding FowardNumber}” CommandParameter=”{Binding Number}” Content=”Save”  Click=”btnSave_Click” Style=”{StaticResource DefaultButtonStyle}” Visibility=”Visible”>
</telerik:RadButton>
</DataTemplate>
</telerik:GridViewColumn.CellTemplate>
</telerik:GridViewColumn>

</telerik:RadGridView.Columns>
<i:Interaction.Behaviors>
<local:EmptyDataTemplateBehavior>
<local:EmptyDataTemplateBehavior.EmptyDataTemplate>
<DataTemplate>
<TextBlock Text=”No results found!” Foreground=”red”  HorizontalAlignment=”Center”  VerticalAlignment=”Center” />
</DataTemplate>
</local:EmptyDataTemplateBehavior.EmptyDataTemplate>
</local:EmptyDataTemplateBehavior>
</i:Interaction.Behaviors>
</telerik:RadGridView>
<telerik:RadDataPager Grid.Row=”1″ PageSize=”20″ DisplayMode=”All” AutoEllipsisMode=”Both” NumericButtonCount=”10″ IsTotalItemCountFixed=”True” Source=”{Binding Items, ElementName=rgdCallForwerding}” />
<telerik:RadBusyIndicator Name=”rbiActivity” BusyContent=”Loading data…” />
</Grid>

</UserControl>

 

 

Client Side

Load RadGridView

 

public void bindCallFoward()
{
//this is show busy icon
this.rbiActivity.IsBusy = true;

//we use service to get record you use which way to access data
ServiceManager manager = ServiceManager.GetServiceManager();
SetMyLeadsWebServiceSoapClient ServiceClient = manager.ServiceClient;
ServiceClient.GetCallForwardcompanyNumberCompleted +=new EventHandler<GetCallForwardcompanyNumberCompletedEventArgs>(ServiceClient_GetCallForwardcompanyNumberCompleted);
ServiceClient.GetCallForwardcompanyNumberAsync(CompanyId, manager.User.Login, manager.User.Password);
}

void ServiceClient_GetCallForwardcompanyNumberCompleted(object sender, GetCallForwardcompanyNumberCompletedEventArgs e)
{
if (e.Error == null)
{

if (e.Result != null && e.Result.Count() > 0)
{

rgdCallForwerding.ItemsSource = e.Result;

}
else
{

rgdCallForwerding.ItemsSource = null;
}

this.rbiActivity.IsBusy = false;
}

}

which check if fowerdnumber cell empty then save button show disable

private void rgdCallForwerding_RowLoaded(object sender, RowLoadedEventArgs e)
{
if (e.Row.DataContext != null)
{
callinnumber cbf = e.Row.DataContext as callinnumber;
var button = e.Row.ChildrenOfType<RadButton>().Where(b => b.Name == “btnSave”).FirstOrDefault();

if (cbf.FowardNumber.Length<=0)
{

button.IsEnabled = false;

}
else
{
button.IsEnabled = true;

}

}
}

 

private void rgdCallForwerding_RowEditEnded(object sender, GridViewRowEditEndedEventArgs e)
{

}

// if you click on empty Call forwerd Cell then enable Save button

I have a RadGridView in which one of the columns contains only buttons.

Depending on the value of a boolean variable linked to a specific record in the grid, I enable or disable the cell containing the button. This is how I achieve this:

private void rgdCallForwerding_SelectionChanged(object sender, SelectionChangeEventArgs e)
{
foreach (callinnumber items in rgdCallForwerding.SelectedItems)
{
//if (rgdCallForwerding.Items.IsEditingItem)
//        {
var    row = this.rgdCallForwerding.ItemContainerGenerator.ContainerFromItem(items) as GridViewRow;

if (row != null)
{

var button = row.FindChildByType<RadButton>();

button.IsEnabled = true;

//var cell = (from c in row.Cells
//            where c.Column.UniqueName == “btnSave”
//         select c).FirstOrDefault();
// if (cell != null)
// {
//     if (items.FowardNumber.Length<=0)
//     {
//         cell.IsEnabled = true;
//     }
//     else
//     {
//         cell.IsEnabled = false;
//     }
// }
}

}

}

 

 

// Save

void btnSave_Click(object sender, RoutedEventArgs e)
{
string _CompanyNumber = “”;
RadButton btnSave = sender as RadButton;
if (btnSave != null)
{

_CompanyNumber = (string)btnSave.CommandParameter;

foreach (callinnumber item in rgdCallForwerding.SelectedItems)
{

Regex regex = new Regex(“^[0-9]*$”);
if (regex.IsMatch(item.FowardNumber))
{
//    if (item.FowardNumber != string.Empty)
//{
if (rgdCallForwerding.Items.IsEditingItem)
{
int _forwardid = item.forwardid;
string _Number = _CompanyNumber;
string _FowardNumber = item.FowardNumber;
int _Companyid = item.Companyid;
ServiceManager manager = ServiceManager.GetServiceManager();
SetMyLeadsWebServiceSoapClient ServiceClient = manager.ServiceClient;
ServiceClient.SaveCallforwardCompleted += new EventHandler<SaveCallforwardCompletedEventArgs>(ServiceClient_SaveCallforwardCompleted);
ServiceClient.SaveCallforwardAsync(_forwardid, _Number, _FowardNumber, _Companyid, manager.User.Login, manager.User.Password);
break;

}

//}
//else
//{
//    MessageBox.Show(“Empty not allowed to Save”);

//}

}
else
{
MessageBox.Show(“Only numbers may be entered here”);

}

}
}

}

private void ServiceClient_SaveCallforwardCompleted(object sender, SaveCallforwardCompletedEventArgs e)
{
if (e.Error == null)
{

MessageBox.Show(“CallFoward Save Successfully.”);

}
bindCallFoward();

}

 

 
Leave a comment

Posted by on January 26, 2012 in Silverlight

 

Tags: , , ,

telerik radgridview export to excel with format


Hi Dear……

if you want to export to excel with ideally in report format then use this code

testexprot.xaml.cs

private void btnExport_Click(object sender, RoutedEventArgs e)
{

ExpExcelReport();

}

private void grdNumbers_ElementExporting(object sender, GridViewElementExportingEventArgs e)
{

if (e.Element == ExportElement.HeaderRow ||
e.Element == ExportElement.HeaderCell)
{
e.FontSize = e.FontSize + 22;
e.FontWeight = FontWeights.Bold;
e.Foreground = Colors.Blue;
e.Background = Colors.DarkGray;
}
//Change the font size and the background color of the group headers only
else if (e.Element == ExportElement.GroupHeaderCell ||
e.Element == ExportElement.GroupHeaderRow)
{
e.FontSize = e.FontSize + 2;
e.Background = Colors.LightGray;
}
else if (e.Element == ExportElement.GroupFooterCell ||
e.Element == ExportElement.GroupFooterRow)
{
e.FontWeight = FontWeights.Bold;
e.FontSize = e.FontSize + 2;
e.Background = Colors.LightGray;
}

}
private void radGridView1_ElementExporting(object sender, GridViewElementExportingEventArgs e)
{

if (e.Element == ExportElement.HeaderRow ||
e.Element == ExportElement.HeaderCell)
{
e.FontSize = e.FontSize + 22;
e.FontWeight = FontWeights.Bold;
e.Foreground = Colors.Blue;
e.Background = Colors.DarkGray;
}
//Change the font size and the background color of the group headers only
else if (e.Element == ExportElement.GroupHeaderCell ||
e.Element == ExportElement.GroupHeaderRow)
{
e.FontSize = e.FontSize + 2;
e.Background = Colors.LightGray;
}
else if (e.Element == ExportElement.GroupFooterCell ||
e.Element == ExportElement.GroupFooterRow)
{
e.FontWeight = FontWeights.Bold;
e.FontSize = e.FontSize + 2;
e.Background = Colors.LightGray;
}

}

private void ExpExcelReport()
{

// this below line write where your reportGrid1 page exist edit his requirment becoz i create control/page/reportfilter seperate folder so i write according my reqirment so changed it
if ((((System.Windows.Controls.ScrollViewer)((System.Windows.Controls.Grid)this.Parent).Parent).Parent as SetMyLeads.Silverlight.UI.Pages.AgentReportingPage).reportGrid1.radGridView1.Items.Count > 0)
{

string extension = “xls”;
SaveFileDialog dialog = new SaveFileDialog()
{
DefaultExt = extension,
Filter = String.Format(“{1} files (*.{0})|*.{0}|All files (*.*)|*.*”, extension, “Excel”),
FilterIndex = 1
};
if (dialog.ShowDialog() == true)
{

int originalPageSize = (((System.Windows.Controls.ScrollViewer)((System.Windows.Controls.Grid)this.Parent).Parent).Parent as SetMyLeads.Silverlight.UI.Pages.AgentReportingPage).reportGrid1.radDataPager1.PageSize;
int originalPageIndex = (((System.Windows.Controls.ScrollViewer)((System.Windows.Controls.Grid)this.Parent).Parent).Parent as SetMyLeads.Silverlight.UI.Pages.AgentReportingPage).reportGrid1.radDataPager1.PageIndex;

using (System.IO.Stream stream = dialog.OpenFile())
{
(((System.Windows.Controls.ScrollViewer)((System.Windows.Controls.Grid)this.Parent).Parent).Parent as SetMyLeads.Silverlight.UI.Pages.AgentReportingPage).reportGrid1.radDataPager1.PageSize = 0;

Telerik.Windows.Controls.GridViewExportOptions options = new Telerik.Windows.Controls.GridViewExportOptions();
Telerik.Windows.Controls.ExportFormat format = Telerik.Windows.Controls.ExportFormat.Html;
options.Format = format;

options.ShowColumnFooters = true;
options.ShowColumnHeaders = true;
options.ShowGroupFooters = true;
options.Encoding = UTF8Encoding.UTF8;

System.Windows.Controls.ListBoxItem selected = lbLinks.SelectedItem as System.Windows.Controls.ListBoxItem;

string unicodeString = ” <b><font size=18 ><center>” + selected.Content.ToString() + “</center></font></b><br>”;
string _DateRange = (unicodeString + “<center><b><font size=4 >Date From: </font></b>” + Convert.ToDateTime(txtfromDate.SelectedDate).ToString(“yyyy-MM-dd”) + ”  ” + “<b><font size=4 >Date To:  </font></b>” + Convert.ToDateTime(txttoDate.SelectedDate).ToString(“yyyy-MM-dd”) + “</center>”);
byte[] title = Encoding.UTF8.GetBytes(_DateRange + System.Environment.NewLine);
stream.Write(title, 0, title.Length);

(((System.Windows.Controls.ScrollViewer)((System.Windows.Controls.Grid)this.Parent).Parent).Parent as SetMyLeads.Silverlight.UI.Pages.AgentReportingPage).reportGrid1.radGridView1.ElementExporting += radGridView1_ElementExporting;

(((System.Windows.Controls.ScrollViewer)((System.Windows.Controls.Grid)this.Parent).Parent).Parent as SetMyLeads.Silverlight.UI.Pages.AgentReportingPage).reportGrid1.radGridView1.Export(stream, options);

}

//Which is use for page which export all pages record of gridview otherwize export first page of grid
(((System.Windows.Controls.ScrollViewer)((System.Windows.Controls.Grid)this.Parent).Parent).Parent as SetMyLeads.Silverlight.UI.Pages.AgentReportingPage).reportGrid1.radDataPager1.PageSize = originalPageSize;
(((System.Windows.Controls.ScrollViewer)((System.Windows.Controls.Grid)this.Parent).Parent).Parent as SetMyLeads.Silverlight.UI.Pages.AgentReportingPage).reportGrid1.radDataPager1.PageIndex = originalPageIndex;

}
}
else
{
MessageBox.Show(“There are no records to export.”, “Export Warning!”, MessageBoxButton.OK);
}

}

 

 
Leave a comment

Posted by on January 26, 2012 in Silverlight

 

Tags: , , , ,