.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

Using MVVM and commands inside of a datatemplate, the command wont execute.

Posted By:      Posted Date: October 21, 2010    Points: 0   Category :WPF
Inside of my main view i have a datatemplate showing off all the items in an observable collection. now inside of that i want to set commanding on a radio button.

outside the datatemplate this works
<Button Height="23" Name="btnUpdate" Command="{Binding UpdateCommand}"

View Complete Post

More Related Resource Links

Binding Command Inside DataGrid Using MVVM

In this post I will show you how to bind the commands inside the data grid control using MVVM pattern. For this post I have continue my last post which is used to explain the data pager using MVVM. For this post I have added DelegateCommand class which is added in the Classes folder. I have only one command in the viewModel (with the name HomeViewModel and is located in the ViewModel folder). The view for the Home is located in the View folder. Here you can see that I have added the HomeViewModel as resource in the home view which you can see in the Image 1.

Again, Getting control inside datatemplate from code behind

HI, All: This problem comes back to bite me again. I had a similar problem before but I changed the customer control to user control and define the click event in the xaml. But this time I have to stick with the customer control. I searched the internet and there are a lot of examples but in my situation, I still got null object. I have a CUSTOMER control which derives from treeview. The hierachicalDataTemplate for the treeview is following:     <HierarchicalDataTemplate         x:Key="CheckBoxItemTemplate"         ItemsSource="{Binding SubFolder}"         >         <StackPanel Orientation="Horizontal">             <CheckBox             x:Name="PART_CheckBox"             Focusable="False"             IsChecked="{Binding IsSelected}"             VerticalAlignment="Center"                 &nbs

can't execute "create table" command with Visual Web Developer express

I have a folder with a web site I'm developing which is connected to a database.Every time I move the folder to a different computer it's a pain when I have to move the database and change the connection string.I've thought to use for the first time a database in the app_data folder and move all the database inside it.Nevertheless, when I try to recreate all the tables in the new database for the first time with the query "create table ..." I get and error saying that "SQL CREATE TABLE" is not supported.Is there a way to manage this situation?--   Giuseppe

Drag and Drop Events binded to MVVM commands

Hi , I am developing the drag n drop functionality.. I want in my drop event my command from MVVM model should fire.. Can you help me in how to Map Drag drop events  into MVVM by Commands...

Execute Command and wait until finished (WMI - ManagementClass)

Hi allI am trying to execute a command on a remote maschineand wait until the command is finished.I can start the process but I do not know how to wait for finish.Thanks for any comment !!!Best regardsFrankHere is what I am doing            System.Management.ConnectionOptions local_Connection = new System.Management.ConnectionOptions();            local_Connection.Username = "some_user";            local_Connection.Password = "some_password";            local_Connection.Authority = "ntlmdomainome_domain";            // ManagementScope erstellen            System.Management.ManagementScope local_Scope = new System.Management.ManagementScope("\\\\servername\\root\\CIMV2", local_Connection);            local_Scope.Connect();            // ManagementClass erstellen            System.Management.ManagementClass local_ClassInstance = new System.Management.ManagementClass(local_Scope, new System.Management.ManagementPath("Win32_Process"), null);            // Create a results and completion handler            System.Management.ManagementOperationObserver local_ClassHandler = new System.Management.ManagementOperationObserver();            // Invoke method asynchronously            System.Management.ManagementBaseObject local_InParams = local_ClassInstance.GetMethodParameters("Create");            local_InParams["CommandLin

WPF, MVVM, Commands from buttons within a Listbox ItemTemplate? (code included)

I want to capture button clicks from within a list item row. Below I have tried to boil the problem down as much as I can. First, here is the xaml <Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" x:Class="test2.MainWindow" x:Name="Window" Title="MainWindow">  <Grid x:Name="LayoutRoot">  <ListView Margin="148,74,0,202" HorizontalAlignment="Left" ItemsSource="{Binding ListData}">   <ListView.View>    <GridView>     <GridViewColumn Header="Item" DisplayMemberBinding="{Binding ItemName}" />     <GridViewColumn Header="Options" Width="200" >      <GridViewColumn.CellTemplate>       <DataTemplate>        <StackPanel Orientation="Horizontal">         <Button Content="Reject" Height="20" Width="80" Margin="5,2" Command="{Binding Commands}" CommandParameter="RejectItem" /> 

Execute inside Execute

Is it possible to use EXECUTE inside an EXECUTE command?  For example, I build a dynamic SQL statement like so:
 SET NOCOUNT ON DECLARE @SQL NVARCHAR(MAX) = ''; SELECT @SQL = @SQL + 'EXEC MSDB.dbo.sp_update_job @job_name = ''' + j.[Name] + ''', @owner_login_name = ''sa''; ' + CHAR(13) FROM MSDB.dbo.sysjobs j   LEFT JOIN Master.dbo.syslogins l     ON j.owner_sid = l.sid WHERE   l.[name] <> 'sa'   OR l.name IS NULL ORDER BY j.[name] PRINT @SQL;
I can execute the statements that come from that manually and everything works... However, if I change that PRINT @SQL to an EXECUTE @SQL, it gives me errors: Msg 203, Level 16, State 2, Line 15 The name 'EXEC MSDB.dbo.sp_update_job @job_name = 'job1', @owner_login_name = 'sa'; EXEC MSDB.dbo.sp_update_job @job_name = job2', @owner_login_name = 'sa'; EXEC MSDB.dbo.sp_update_job @job_name = 'job3', @owner_login_name = 'sa'; ' is not a valid identifier. Is this because you can't do an EXECUTE inside an EXECUTE?  Is there any way to do what I'm trying to do which is enumerate all SQL jobs that don't have an owner of 'sa' and update them so they do? Number2 - (John Nelson) Microsoft MVP (2009) - System Center Configuration Manager http://number2blog.com

ListView.ItemTemplate with Button. Command doesn't execute when item is selected

I have a listview with an item template that contains a button: <ListView ItemsSource="{Binding AllProducts}"> <ListView.ItemTemplate> <DataTemplate> <Grid> <Button Content="Add Supplier" Command="{Binding AddSupplier}"/> </Grid> </DataTemplate> </ListView.ItemTemplate> </ListView> When the listitem is not selected and the button is clicked, the command executes fine. However, if the listitem is selected, the command does not execute. I have tried putting click and mouse down event handlers on the button, but the events do not fire. Is there any way to make the command execute when the listitem is selected?

How to disable delete command for certain activities inside the composite activity



I had build up a composite activity, this composite activity basically contains a few activities, some of the activities are not allowed to delete. Is there a way to disable the delete command using WF APIs, instead of hooking up the keydown and context menu event for those activities?


SQL Command Or Stored Procedure in Execute SQL Task


Hi all,

Which is a better way to do in Execute SQL Task : Direct SQL input or Create a stored proc in database and then use that.

In my opinion, Stored Procedure is a better and recommended way for following reasons:

  • Cached execution plan
  • More secure
  • Centralized code
  • Code reuse

Please let me know if this is not the case with SSIS Execute SQL Task.


The data source control failed to execute the insert command


Hi All,

I have create table in SQL 2005 and retrive its data in to sharepoint  with the help of Database connection option through Sharepoint Designer. When configuring the connection i have selected a custom quer with stored procedure option and from the dropdown option selected the insert stored procedure everything is ok.

Stored Procedure
CREATE PROCEDURE ChangeTable_insert

 @PROJECT varchar(50) ,

INSERT INTO [dbo].[ChangeTable]





i have created new aspx page in Sharepoint Designer from the datasource details-->Insert selected fields as-->selected new item form and saved this page.
When i opened this page in to browser and try to save data it gives an below error
Go back to site 
Error: "The data source control failed to execute the insert command.
 Troubleshoot issues with Windows SharePoint Services."

please help me. i have to save data to sql database through sharepoint

thanks in advance

binding to properties inside a datatemplate


Hi all


Im creating a user control which will act like a border.  I will be able to specify via properties each side of the borders thickness and color.  I am using a DataTemplate for this because I want to be able to specify where I want the content to go inside the user control.


My problem is I can’t seem to get the properties iv created in code (get;set) to change the thickness or color or the borders iv created in the xaml file.  Iv tried binding to them in the xaml file however they are not getting called.



Execute DOS Command with Variable



I am using 2 task in control flow.

1st task is a "execute SQL task" which returning from DB into a variable called VAR1(i.e. VAR1 = C:\test_data\)

2nd task is "execute process task" where I wnat to delete all the files from the directory (i.e. value got in VAR1)

Pls help.

Many Thanks,





Need to execute ALTER DATABASE inside stored procedure


SQL 2005 Standard.

I wrote a sp that uses ALTER DATABASE instruction. When I execute sp with elevated user it works fine; when I try to execute that sp with a normal user (I alerady gave execute permission for that user) it fails with "alter database failed".

I tried to modify create proc with execute as owner but nothing changed.

How can I do ?


Command inside WPF 4 DataGrid RowDetailsTemplate Not firing


Hi all,

I am using VS2010 WPF4 + Prism 2.2 to build my application. In oder to demo the issue, I built a very simple application here:

The Xaml of window (MainWindow.xaml), I defined a DataGrid and a button. I bind command of button inside row details to a DelegateCommand defined in ModelView, I also bind button (below the DataGrid) to another command.

<Window x:Class="WpfApplication1.MainWindow"

Passing Parameters to Execute SQL task which is inside a For Loop Container



I have a requirement.

In this I will get a value of 50 ids from one table.

I have an sp which will take ids as input parameter and insert values into another table.

My Problem is I am having a for loop container with me and inside that i have execute sql task in which I have stored procedure.

How can i map the id parameter to the execute sql task variable whichi is inside a forloop.




Thanks, A2H

Dynamic Sub Menu Item Command Not working in WPF...MVVM

<MenuItem Header="Flag(s)" ItemsSource="{Binding Path=LineItemFlags}" >
                                <Style TargetType="{x:Type MenuItem}">
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend