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


Top 5 Contributors of the Month
david stephan

Home >> Forum >> Silverlight >> Post New QuestionBookmark and Share Subscribe to Forum

c# code for datagrid with delete button in silverlight

Posted By: sudhakarreddy     Posted Date: May 14, 2010    Points:2   Category :Silverlight
After check the check boxes (one or more) in the datagrid, i have to delete those rows from the datagrid by clicking the delete button

i want code for following requirements simply
(Check the Rows, execute the query to delete the rows, then rebind the grid)
1) First get the Selected Checked Row items.
2) Delete the records in the DB
3) Rebind the Datagrid

Responses
Author: Lalij Mer             
Posted Date: May 14, 2010     Points: 5   

show here grate article will help

http://geekswithblogs.net/dotNETvinz/archive/2009/02/22/gridview-multiple-delete-with-checkbox-and-confirm.aspx

Please Check my answer if you help....
Thank You...

Lalit.
Author: Sunil Yadav       [Moderator]      
Posted Date: May 27, 2010     Points: 5   

Hi,

Check out this..

<data:DataGrid x:Name="dgAssets" ItemsSource="{Binding Data, ElementName=ddsAsset}"
SelectionChanged="dgAssets_SelectionChanged"

IsReadOnly="True" AutoGenerateColumns="True"
Margin="-209,8,-258,-41" HeadersVisibility="All"/>



<Button x:Name="btnDeleteAsset" Click="btnDeleteAsset_Click" Height="24" Margin="0,0,8,8" VerticalAlignment="Bottom" Content="Delete"/>


private void btnDeleteAsset_Click(object sender, System.Windows.RoutedEventArgs e)
{
if (dgAssets.SelectedIndex != -1)
{
int assetid = ((TBAssetRegister)(dgAssets.SelectedItem)).AssetID;

TBAssetRegister objTBAssetRegister = new TBAssetRegister();

var context = ddsAsset.DomainContext as AppDomainContext;

var v = context.TBAssetRegisters.SingleOrDefault(p => p.AssetID == assetid);
objTBAssetRegister = v;
IEditableObject Selectedasset = dgAssets.SelectedItem as TBAssetRegister;
Selectedasset.CancelEdit();

context.TBAssetRegisters.Remove(v);
context.SubmitChanges();
}

}
Hope it helps.



Post Reply

You must Sign In To post reply
 
 
Find more Forum Questions on C#, ASP.Net, Vb.Net, SQL Server and more Here
Quick Links For Forum Categories:
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  OOPs  SilverlightIISJQuery
JavaScript/VBScriptBiztalkWPFPatten/PracticesWCFOthers
www.DotNetSpark.comUnAnsweredAll

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