Here is the code I am using for delete functionality.
In RadgridItemdatabound funtion, I have to include this...
foreach (GridColumn col in RadGrid1.MasterTableView.Columns)
{
dataItem["TemplateDeleteColumn"].Attributes.Add("onclick","CellClick('" + dataItem.ItemIndex + "','" + col.UniqueName + "');");
}
Then I have to create Itemcommand function.
protected void RadGrid1_ItemCommand(object sender, GridCommandEventArgs e)
{
if (e.CommandName == "DeleteSelected")
{
GridDataItem item = (GridDataItem)e.Item;
var itemIndex = item.ItemIndex;
string LoginId = item.GetDataKeyValue("LoginId").ToString();
Int32 CampusCode = Convert.ToInt32(item.GetDataKeyValue("CampusCode"));
Definations def = new Definations();
Int32 Result = def.deleteUserAssignCampus(LoginId, CampusCode);
if (Result == 1)
{
BindDeptDatasimple();
cmbColumName.SelectedValue = "";
cmbDirection.SelectedValue = "";
Response.Redirect("UserCampus.aspx", false);
Session["deleteUserCampus"] = "Campus dissociated successfully.";
}
}
}
I could not get index of the selected row in the "var ItemIndex". It always return zero index in ItemIndex. That's why the first row from the grid gets deleted. How I can get selected Index of selected row?