RSS

Monthly Archives: March 2012

How to set image source code behind in silverlight


Hi  Dear…

if your want to change image dynamically of RadGridview in Silverlight with specific Condition then your use this code and be happy

ClientSite

<telerik:GridViewColumn Width=”auto”>
<telerik:GridViewColumn.CellTemplate>
<DataTemplate>

<telerik:RadButton  x:Name=”lbtnInActive”   Command=”Edit” CommandParameter=”{Binding Listidpk}” Click=”lbtnInActive_Click”  >
<telerik:RadButton.Content>
<StackPanel Orientation=”Horizontal” Margin=”0″>
<Image Source=”../Images/icon-Active.png” Width=”30″ Height=”31″ x:Name=”activeICon”/>
</StackPanel>
</telerik:RadButton.Content>
</telerik:RadButton>
</DataTemplate>
</telerik:GridViewColumn.CellTemplate>
</telerik:GridViewColumn>

CodeBehind:

private void grdList_RowLoaded(object sender, Telerik.Windows.Controls.GridView.RowLoadedEventArgs e)
{
if (e.DataElement != null)
{
if (e.Row.DataContext != null)
{
var button = e.Row.ChildrenOfType<RadButton>().Where(b => b.Name == “lbtnInActive”).FirstOrDefault();
var imgicon = e.Row.ChildrenOfType<Image>().Where(b => b.Name == “activeICon”).FirstOrDefault();
tbllists tblst = e.Row.DataContext as tbllists;

if (Convert.ToString(tblst.Liststatus)== “Active”)
{
button.Tag = “Active”;
ToolTipService.SetToolTip(button, “Change Status To InActive”);
imgicon.Source = new BitmapImage(new Uri(“../Images/icon-Active.png”, UriKind.RelativeOrAbsolute));

}
else if (Convert.ToString(tblst.Liststatus)==”InActive”)
{

button.Tag = “InActive”;
ToolTipService.SetToolTip(button, “Change Status To Active”);
imgicon.Source = new BitmapImage(new Uri(“../Images/icon-inactive.png”, UriKind.RelativeOrAbsolute));

}
else {
button.Tag = “Active”;
imgicon.Source = new BitmapImage(new Uri(“../Images/icon-pending.png”, UriKind.RelativeOrAbsolute));
ToolTipService.SetToolTip(button, “Change Pendding To Active”);
}

}
}
}

 

 
Leave a comment

Posted by on March 30, 2012 in Silverlight

 

Tags: , , , , ,

add special char in header RadMenuItem


Special Characters:

Some browsers return escaped text while others return unescaped text. Below is an example of HTML code, how it’s displayed in IE, and how it’s rendered in the DOM Explorer.

 

 

<telerik:RadMenuItem Header=”ReportingPage2″ x:Name=”MyReportingPage2″>

<telerik:RadMenuItem x:Name=”hbtnCampaignSales” Tag=”ReportingPage2/2″

Header=”Campaign &amp; Sale”

Click=”hbtn_Click” Style=”{StaticResource ChildRadMenuItemStyle}” />

</telerik:RadMenuItem>

 

 
Leave a comment

Posted by on March 21, 2012 in Silverlight

 

Tags: , ,

How can i set ToolTip in CodeBehind using Silverlight


hi dear……

ToolTipService.SetToolTip(btnButtonName, “Disable Due to Campaign Currently ” );

 showing a tooltip for disabled control in silverlight CodeBehind

private void grdcampaign_RowLoaded(object sender, RowLoadedEventArgs e)
{

if (e.DataElement != null)
{
if (e.Row.DataContext != null)
{
var btnDelete = e.Row.ChildrenOfType<RadButton>().Where(b => b.Name == “btnDelete”).FirstOrDefault();
var btnView = e.Row.ChildrenOfType<RadButton>().Where(b => b.Name == “btnView”).FirstOrDefault();

//btnView6
tblcampaign tblst = e.Row.DataContext as tblcampaign;
if (Convert.ToString(tblst.Status) != “Pending”)
{

btnView.IsEnabled = false;
//this Line Show the Tooltip of Disable Button
ToolTipService.SetToolTip(e.Row.Cells[8], “Campaign Currently  ” + tblst.Status);

}
else
{
btnView.IsEnabled = true;
ToolTipService.SetToolTip(btnView, “Campaign Currently  ” + tblst.Status);

}

}
}

}

                     //How can i find RadGridview or datagridview Button Codebehind in Silverlight

var btnDelete = e.Row.ChildrenOfType<RadButton>().Where(b => b.Name == “btnDelete”).FirstOrDefault();

.xaml Side

<telerik:RadGridView x:Name=”grdcampaign” Grid.Row=”2″ Grid.Column=”0″ IsFilteringAllowed=”False”
LoadingRowDetails=”grdcampaign_LoadingRowDetails” RowLoaded=”grdcampaign_RowLoaded”
ColumnWidth=”*”    RowIndicatorVisibility=”Collapsed”
IsReadOnly=”True” AutoGenerateColumns=”False” CanUserFreezeColumns=”False”
CanUserResizeColumns=”False” MinWidth=”1000″  Style=”{StaticResource DefaultGridStyle}”>

<telerik:RadGridView.Columns>
<telerik:GridViewToggleRowDetailsColumn />
<!–<telerik:GridViewImageColumn IsGroupable=”False” IsSortable=”False”
DataMemberBinding=”{Binding Image}” Width=”50″ ImageHeight=”40″ ImageWidth=”40″ />–>
<telerik:GridViewDataColumn UniqueName=”Campaigndesc” Header=”Campaign Name” Width=”.2*”/>
<telerik:GridViewDataColumn UniqueName=”CompanyName” Header=”Company Name” Width=”.1*” />

<telerik:RadButton x:Name=”btnView” Command=”Edit”
CommandParameter=”{Binding Campaignidpk}” BorderThickness=”1″
ToolTipService.ToolTip=”View Leads”  Click=”RadButton_Click”>
<telerik:RadButton.Content>
<StackPanel Orientation=”Horizontal” Margin=”0″ x:Name=”btnView6″  >
<Image Source=”../Images/icon-view.png” Width=”15″ Height=”15″/>
</StackPanel>
</telerik:RadButton.Content>
</telerik:RadButton>
</DataTemplate>
</telerik:GridViewColumn.CellTemplate>
</telerik:GridViewColumn>

<telerik:GridViewColumn Width=”28″>
<telerik:GridViewColumn.CellTemplate>
<DataTemplate>
<telerik:RadButton  x:Name=”btnDelete” Command=”Delete”
CommandParameter=”{Binding Campaignidpk}”
BorderThickness=”1″ Click=”btnDelete_click” ToolTipService.ToolTip=”Delete” >
<telerik:RadButton.Content>
<StackPanel Orientation=”Horizontal” Margin=”0″>
<Image Source=”../Images/icon-delete.png” Width=”15″ Height=”15″/>
</StackPanel>
</telerik:RadButton.Content>
</telerik:RadButton>
</DataTemplate>
</telerik:GridViewColumn.CellTemplate>
</telerik:GridViewColumn>

</telerik:RadGridView.Columns>
<telerik:RadGridView.RowDetailsTemplate >
<DataTemplate>

<StackPanel Orientation=”Horizontal” HorizontalAlignment=”Stretch”  Margin=”5″ MinWidth=”800″>
<my1:ListCampaignDetail x:Name=”ListCampaignDetail1″ MinWidth=”800″/>

</StackPanel>

</DataTemplate>

</telerik:RadGridView.RowDetailsTemplate>

<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.Column=”0″ Grid.Row=”3″ PageSize=”20″ DisplayMode=”All”
AutoEllipsisMode=”Both” NumericButtonCount=”10″ IsTotalItemCountFixed=”True”
Source=”{Binding Items, ElementName=grduser}” />

//How To Get ID of Selected Row in RadGridView

RadButton btnEdit = sender as RadButton;
int Cid = Convert.ToInt32(btnEdit.CommandParameter);

 
Leave a comment

Posted by on March 20, 2012 in Silverlight

 

Tags: , ,

where clause on object C# silverlight


LINQ where clause with lambda expression  With Specific Keyword Show the Data in Silverlight or in WebService

if your create a class object an after filled then your want to load all data from db and restrict on specific keyword data not show ,so you need to apply this method.

Where(x => x.Status != “Complete”).ToList();

if you not use toList() then give you Casting Error so, must use this

This is WebServices Method in silverlight

public List<tblTest> GetCampaignByCompanyId(int companyid)
{
List<tblcampaign> lst = new List<tblcampaign>();

tblcampaign c = new tblcampaign();
c.GetAllCampaignByCompanyId(companyid);
if (c.RowCount > 0)
{
lst = tblcampaign.PopulateCampaign(c).Where(x => x.Status != “Complete”).ToList();
}

return lst;
}

 

or

 

// u.DataTable.Select(“RoleID in (3,4) and isdeleted=0”)

 
Leave a comment

Posted by on March 13, 2012 in Silverlight

 

Tags: ,

change tooltips from codebehind silverlight


You can set or change Tooltips from the code behind file.How can i write a code for ToolTip in Code Behind ,so follow this…

ToolTipService.SetToolTip(ButtonName, "This is new tooltip");

find control from codebehind from silverlight:
var button = e.Row.ChildrenOfType<HyperlinkButton>().Where
(b => b.Name == "lbtnStarted").FirstOrDefault();

 //front side
 <telerik:GridViewColumn Width=".2*">
<telerik:GridViewColumn.CellTemplate>
<DataTemplate>
<HyperlinkButton x:Name="lbtnStarted" Content="" 
CommandParameter="{Binding Pkcampaignid}" 
Click="lbtnStarted_click" ToolTipService.ToolTip="Change Status">
</HyperlinkButton>
</DataTemplate>
  </telerik:GridViewColumn.CellTemplate>
 </telerik:GridViewColumn>

//Codebehind

 private void grdcampaign_RowLoaded(object sender,
 Telerik.Windows.Controls.GridView.RowLoadedEventArgs e)
        {
            if (e.DataElement != null)
            {
                if (e.Row.DataContext != null)
                {
  var button = e.Row.ChildrenOfType<HyperlinkButton>().Where
(b => b.Name == "lbtnStarted").FirstOrDefault();
                    tblcampaign tblst = e.Row.DataContext as tblcampaign;

                    if (Convert.ToString(tblst.Status) == "Running")
                    {
                        button.Content = "Stopped";

ToolTipService.SetToolTip(button, "Change Status to Started");
                    }
                    else if (Convert.ToString(tblst.Status) == "Stopped")
                    {
        ToolTipService.SetToolTip(button, "Change Status to Stopped");
                        button.Content = "Started";
                    }
                    else if (Convert.ToString(tblst.Status) == "Pause")
                    {
      ToolTipService.SetToolTip(button, "Change Status to Started");
                        button.Content = "Started";
                    }

                }
            }
        }
 
Leave a comment

Posted by on March 10, 2012 in Silverlight

 

Tags: , , , , ,

upload csv file in silverlight


upload csv file in silverlight with header.

read csv file and write into database with class…….

//Create List with class

List<tbltest> lArrObjclsGridLoadExcelData = new List<tbltest>();

//Read CSV File and write in class
public void lFnLoadCSVDataInGrid()
{
try
{

lArrObjclsGridLoadExcelData.Clear();
int j = 1;

OpenFileDialog dlgOpen = new OpenFileDialog();
dlgOpen.Filter = “CSV Files (*.csv)|*.csv”;
bool? res = dlgOpen.ShowDialog();

if (res == true)
{

txtCSV.MaskedText = dlgOpen.File.Name;
txtCSV.IsReadOnly = true;

StreamReader lObjStreamReader = new StreamReader(dlgOpen.File.OpenRead());

bool lBlnIsColumnRow = true;

while (lObjStreamReader.Read() != null)
{
string lStrLine = lObjStreamReader.ReadLine();

if (lBlnIsColumnRow)
{
lBlnIsColumnRow = false;
continue;
}

if (lStrLine == null)
break;

if (lStrLine.Trim() == “”)
continue;

string[] lArrStrCells = null;

lArrStrCells = lStrLine.Split(“,”.ToCharArray());

if (lArrStrCells == null)
continue;

if (!(lArrStrCells.Length == 11))
continue;

tbltest lObjclsGridLoadExcelData = new tbltest();

lObjclsGridLoadExcelData.Leadidpk = j;
lObjclsGridLoadExcelData.Listidfk = j;

lObjclsGridLoadExcelData.Phonecode = Convert.ToSByte(lArrStrCells[0]);
lObjclsGridLoadExcelData.Phonenumber = lArrStrCells[1];
lObjclsGridLoadExcelData.Title = lArrStrCells[2];
lObjclsGridLoadExcelData.Firstname = lArrStrCells[3];
lObjclsGridLoadExcelData.Lastname = lArrStrCells[4];
lObjclsGridLoadExcelData.Surename = lArrStrCells[5];
lObjclsGridLoadExcelData.Address1 = lArrStrCells[6];
lObjclsGridLoadExcelData.Address2 = lArrStrCells[7];
lObjclsGridLoadExcelData.City = lArrStrCells[8];
lObjclsGridLoadExcelData.State = lArrStrCells[9];
lObjclsGridLoadExcelData.Zip = lArrStrCells[10];
lObjclsGridLoadExcelData.Datetimecallback = DateTime.Now;
lObjclsGridLoadExcelData.Comments = “”;
lObjclsGridLoadExcelData.Agent = “sajjad”;
lObjclsGridLoadExcelData.Attempts = 2;

lArrObjclsGridLoadExcelData.Add(lObjclsGridLoadExcelData);

j++;
}

lObjStreamReader.Close();
lObjStreamReader.Dispose();

}
//  return lArrObjclsGridLoadExcelData;
}
catch (Exception ex)
{
//  lFnShowPopupErr(ex.Message.ToString());
// return null;
}
}

 

 

load csv in datagrid

 

private void btnUpload_Click(object sender, RoutedEventArgs e)
{

try
{
lFnLoadCSVDataInGrid();
       grdList.ItemsSource = lArrObjclsGridLoadExcelData.ToList();
}

catch (Exception)
{
throw;

}

}

 
Leave a comment

Posted by on March 10, 2012 in Silverlight

 

Tags: , , ,

Download CSV File in Silverlight


Hi…

you can download csv,excel or image file like jpg ,jpeg,bmp or any formate file from server on local system then

you just use this code and resolve your problem.

This line below find out the actual path of application

 string str = App.Current.Host.Source.AbsoluteUri;

// you can replace and get the path of specific folder and file with in it.

str = str.Replace(“ClientBin/SetMyLeads.Silverlight.UI.xap”, “Samplecsv/Sample.csv”);

 

 

 

 

 

 

 

 

 

private void sampleupload_Click(object sender, RoutedEventArgs e)
{

SaveAs();

}

public void SaveAs()
{
SaveFileDialog dialog = new SaveFileDialog();
dialog.Filter = “csv Files|*.csv”;

bool? dialogResult = dialog.ShowDialog();

if (dialogResult != true) return;

WebClient webClient = new WebClient();
webClient.OpenReadCompleted += (s, e) =>
{
try
{
using (Stream fs = (Stream)dialog.OpenFile())
{
e.Result.CopyTo(fs);
fs.Flush();
fs.Close();
}

}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
};
string str = App.Current.Host.Source.AbsoluteUri;
str = str.Replace(“ClientBin/SetMyLeads.Silverlight.UI.xap”, “Samplecsv/Sample.csv”);

webClient.OpenReadAsync(new Uri(str), UriKind.Absolute);
}

 

 
Leave a comment

Posted by on March 10, 2012 in Silverlight

 

Tags: , , , , , , , , ,