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

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

DataGrid ItemDataBound Event Calls

Posted By:      Posted Date: September 23, 2010    Points: 0   Category :ASP.Net

how many times itemDataBound event calls exactly, if my datatable have 2 records it is calling 4 times , first time in item index 0 , second time it is 1 and third time again it contains index 0 and forth time it is 1. 

so, could anyone please help me how the itemdatabound event actually works,

highly appreciate for any comment.

View Complete Post

More Related Resource Links

Update datagrid and Event-Based Async calls


I’m using a datagrid (actually Infragistics XamGrid) which is bound to a custom list of business objects.  In the old WPF days, when completing the edit of a grid row, the business object’s EndEdit() method would be called via databinding.  The EndEdit() method would then save the data to the db via a web service call.  The retuning result of the web service call would tell the business object (in the EndEdit() method) of the call succeeded or failed.  If it failed, it would roll back the changes and raise an event to alert the UI.

In the world of Silverlight and Event-Based Async calls, it’s not possible to do all of this from in the EndEdit() method.

Also, I’m generating my web services using the SLsvcUtil.exe tool.  Since MS is forcing us to use Async calls, then what is the standard way to update data from a gird row and then roll it back and alert the UI when the call fails?

I found a nice article http://blog.jayway.com/2010/06/10/silverlight-prefer-synchronous-web-service-calls/ about making synchronous web service calls in SL, but the catch is that can’t be on the UI thread which – updating a gird row will be on.

Please relay any advice and resources you can offer!


How to get the combobox value inside Datagrid on Edit button click event

Hi     I have Datagrid template column like<DataGridTemplateColumn.CellTemplate></DataGridTemplateColumn>DataGridTemplateColumn Header="Edit" x:Name="Edit" ><DataGridTemplateColumn.CellTemplate></DataGridTemplateColumn.CellEditingTemplate></DataGridTemplateColumn>SelectionChanged="cmbDGTeam_SelectionChanged" IsTabStop="True" /></DataTemplate><ComboBox Height="22" IsEditable="True" IsReadOnly="True" ItemsSource="{Binding}" DisplayMemberPath="Title" SelectedValuePath="TeamID" x:Name="cmbDGTeam"  SelectedValue="{Binding Path=TeamID,Mode=TwoWay}"<DataGridTemplateColumn.CellEditingTemplate><DataTemplate><DataTemplate><TextBlock Text="{Binding Title}"/></DataTemplate></DataGridTemplateColumn.CellTemplate><DataGridTemplateColumn Header="Team" Width="75"><DataGridTemplateColumn.CellTemplate> and Edit button Template column <DataGridTemplateColumn Header="Edit" x:Name="Edit" > </DataGridTemplateColumn.CellTemplate></DataTemplate><Button Content="Edit" IsEnabled="False" x:Name="btnEdit" Click="btnEdit_Click" ></Button>&l

DataGrid Button + event in Footer, event not getting fire!

hi.First Time i am trying this...I have one Datagrid with Footer. Footer Row Contains Input fields with one Button to add New Values. I have button click event but not getting fires. my code follows:protected void dgPrice_ItemCreated(object sender, DataGridItemEventArgs e)    {            Button btnAdd = new Button();            btnAdd.Text = "Add";            btnAdd.Width = 80;            btnAdd.ID = "btnAdd";           // btnAdd.Attributes.Add("onClick", "return validateRates()");            btnAdd.CommandName = "add";            btnAdd.CommandArgument = e.Item.ItemIndex.ToString();            btnAdd.Command +=new CommandEventHandler (PriceNew);            e.Item.Cells[6].Controls.Add(btnAdd);}protected void PriceNew(object sender, EventArgs e)    {}btnAdd.command/ btnAdd.click event not getting fired I also tried to

Create an Event Handler to catch calls to Create.aspx

Hi, I want to research creating an event handler/reciever to catch calls (mouse clicks) to Create.aspx to prevent users having the ability to create new content. I've noticed in VS2010 the templates for Event Recivers you do not get anything similar that I could use as a starting point (List Events, List Item Events etc) Any ideas how I can define a new type of event receiver?

How to stop Datagrid SelectionChange from SelectionChanged Event



I have a DataGrid which is binded with a List. Consider I have 10 Items in the List, so in the combobox also.

Currently 2nd Item is selected in the DataGrid.

Now I am selecting the 3rd item in the DataGrid.

In the DataGrid SelectionChanged event, I am doing some validation and validation fails so I don want my Selection is changed from 2nd item to 3rd item or the selection should remain in 2nd item.

Please let me know how to do this?

In the DataGrid SelectionChanged event, I tried to set DataGrid.SelectedItem = 2ndItem.

But this didn't work properly.

Hope, my requirement is clear. If you have any doubt then please feel free to ask me.



WPF Datagrid SelectionChanged event is triggering Multiple times while loading the rows.



When i use DataGridComboBoxColumn in my WPF DataGrid, the DataGrid SelectionChanged event is triggering multiple times based on the number of rows while loading the rows in the WPF DataGrid.

How can i stop this? Because of this I am facing Performance issue.



Please remember to click "Mark as Answer" on the post that helps you, and to click "Unmark as Answer" if a marked post does not actually answer your question. This will help other members to find the solution easily.

DataGrid control properties not updating on resize event


I have a DataGrid control on a form and I'm binding it to an ArrayList that is populated dynamically as the user scrolls.  The array list is pre-populated with blank records equal in number to the number of records in the DB.  As the user scrolls, if they stop in a place where there are blank records I populate that data from the DB.  I'm using the VisibleRowCount and VertScrollBar.Value properties to determine where I am in the DataGrid.  


The problem is that if I scroll to the bottom of the control then maximize the control it's resize event fires, the VertScrollBar is redrawn proportionally to the number of records, but the Value and VisibleRowCount remain unchanged.  If I then grab and scroll the scroll bar up then back down to the bottom, the Value and VisibleRowCount update correctly.  Is there a way for me to get these values some other way or to force the scroll bar to refresh/update manually?

WPF DataGrid ItemDataBound



I want to create a DataGrid that consists of 3 TextBox columns and a ComboBox column.

The DataGrid should initially contain one empty row. Whenever the text is changed in any textbox in the first row, a new row should be added to the datagrid. and so on.

How to append events on each control in the created rows? is there ItemDataBound or similar events to append events dynamically?

Datagrid + Mouse right click event


I have a datagrid and it contains the list of files from the folder. I want to display the default window files right click options in right click on the filename.

That is when ever i right click the filename in the datagrid, a default windows right click pop up should appear.


Can anyone help me to sort this out. The project is in C#.

Thank you.

Saugat K.C.

KeyUp event on DataGrid cell or column




I've a DataGrid in my wpf, and I'm creating my columns dynamically via code,

i want to handle the key event on the dataGrid column.

how can i handle event on dataGrid column (something like dataGridView has in winforms).

here is an example:

col = new DataGridTextColumn();
            col.Header = "sum";
            col.Width = new DataGridLength(15, DataGridLengthUnitType.Star);
            col.Binding = new Binding("sum");




WPF Datagrid, raising "RowEditEnded" event


I know that WPF datagrid has "RowEditEnding" event , but I need to fire the event on after the Row has comitted to check if the newly added row is duplicated and merge the duplicated row. My datagrid has "CanUserAddRow" property set to True.

I am using EntityObservableCollection that extends ObservableCollection to synchronize my entity with the collection. So, i considered OnCollectionChanged event, but the "InsertItem" event is raise once user click on the new item place holder row, which means the object is still empty and I cant check for duplicate. I also considered CollectionView CurrentItemChanged event, but it does not provide the behavior I wished.



//my Model class

public class InventoryIngredient : EntityObject, IDataInfoError{

# region properties

public Guid InventoryIngredientID;
public Guid IngredientID;
public Guid UnitID;
public string

Setting focus on cell in datagrid after CollectionChanged event.




Having trouble setting the focus on a cell after the collection recieves a new row. This is my code:

 sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
			DataGridRowObjects<My_DataGridRow> oc = (DataGridRowObjects<My_DataGridRow>)sender;
 (e.Action == NotifyCollectionChangedAction.Add)
				//set focus to column 2 of the new row

				DataGridCell cell = my_datagrid.GetCell(e.NewStartingIndex, 2);
 (cell != null
				 DataGridCellInfo info = new
				 my_datagrid.CurrentCell = info;

Is there any event that fires after the CollectionChanged? My DataGridRow doesn't have a CellPresenter att this stage and GetCell fails. If I do the same with a button event instead, it works fine.

I just tried to add a dispatcher message instead but that did nothing:

Dispatcher.BeginInvoke(new Action(delegate()
  //set focus to column 2 of the new row
  DataGridCell c

WPF DataGrid Add Row Event



I want to add an event to WPF that fires whenevr the user moves to another row or adds a new row in the DataGrid.

How do I do that?

listView - ItemDataBound event - problem casting to DataRowView to get to underlying data?


System.InvalidCastException was unhandled by user code
  Message="Unable to cast object of type 'WebSTAR.JobListItem' to type 'System.Data.DataRowView'."
       at WebSTAR.Default.ListViewRecentJobs_ItemDataBound(Object sender, ListViewItemEventArgs e) in C:\Users\djc\Documents\Visual Studio 2008\Projects\WebSTAR\WebSTAR\Default.aspx.cs:line 255
       at System.Web.UI.WebControls.ListView.OnItemDataBound(ListViewItemEventArgs e)

How do I make a DataGrid fire an event when a cell is changed?


I tried to figure this out a while ago but gave up - now I'm in a situation where I need to try again.

I have a DataGrid (using .NET 4) and I'm trying to fire an event when a cell is changed.  However, I cannot generate any events until a different row is selected.  So, for example, I have a datagrid with a checkbox column and I want an event to occur when the user changes one of the checkboxes.  As it is right now, I can't generate an event until the user selects another row after changing the checkbox.

I've tried every type of event I can find - RowEditEnding, CellEditEnding, CurrentCellChanged, MouseLeftButtonUp, MouseLeftButtonDown, etc.  None is ever fired when the checkbox is changed - they don't fire until another row is selected.

So, I can click away on a checkbox hundreds of times and no events will be generated.  As soon as I change rows, though, the events occur.

Any help with this one?  This is such an elementary problem I'm sure there's something basic I'm missing.  Suffice it to say, I don't use WPF very often :)  I've seen the same question asked elsewhere and there are supposed answers but they are extremely complicated and I can't get them to work.

Thanks in advance,


The number of calls to the Changed event for a single update in the data exceeded the maximum limit.


Dear All,

We have hit the big limit of 16 change events per single update.  Is there any way to extend this to say 25, we are not using infinate loops or anything.

Alternatively, is it possible to disable some change events when values are updated?


William Man

Event about wpftoolkie's datagrid


Here is a datagrid:

<my:DataGrid >
            <my:DataGridTextColumn  Header=" Id" Binding="{Binding Id }"   x:Name="idCol"  />
            <my:DataGridTextColumn Header=" Roomname" Binding="{Binding Roomname }" x:Name="Roomname"/>


I expect the second column's value will change according to the firse column,but i can't find the 'valueChang' event of the DataGridTextColumn.

I'm a beginner,please tell me how to accomplish this function.

Thanks to everybody help!

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