954,580 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Problem getting the row index of a datagrid

Hi all,
I have a CheckBox in a datagrid called DataFinAdjust. The Autopostback properties of the checkbox is set to true. At each post back i want to be able to do an update using other columns of the datagrid as unique identifiers. The challenge i have is that the ItemCommand event is not fired when the checkbox is either checked or unchecked. And figured out that if i used the checkedchanged event of the checkbox i'll have difficulty to get the row index of the datagrid at which the checkbox was checked or unchecked.
My code is as follow sombody please help.

protected void DataFinAdjust_ItemCommand(object source, DataGridCommandEventArgs e)
	   {
	   	var FieldID =  e.Item.Cells[13].Text;
	   	var Account = e.Item.Cells[14].Text;
	   	var cotflag = (CheckBox) e.Item.Cells[7].FindControl("chkcotflag");

	   	var fincost = new FinancialCostAdjustment(appConfiguration.ConnectionString)

					{
					    AcctCode = Account,
					    cotflag = cotflag.Checked,
					    ID = Convert.ToInt32(FieldID)
					};
	   	  fincost.UpdateCOTFLAG();

	   }
ema005
Newbie Poster
24 posts since Jan 2006
Reputation Points: 10
Solved Threads: 4
 

Do you have a column set as a datakey for the gridview? You usually need one for what you're trying to do.

alc6379
Cookie... That's it
Team Colleague
2,820 posts since Dec 2003
Reputation Points: 186
Solved Threads: 147
 

No. I'm not using datagridview but datagrid.

ema005
Newbie Poster
24 posts since Jan 2006
Reputation Points: 10
Solved Threads: 4
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You