Hi
I have below code but RowCommand not getting executed
protected void grdPlanning_RowCommand(object sender, GridViewCommandEventArgs e)
{
try
{
BALBooks bALBooks = new BALBooks();
BALStudents bALStudents = new BALStudents();
StudentDetail Result = bALStudents.GetStudentDetailByLoginID(bALStudents.GetStudentIDByMobile(hdfMobile.Value));
ltrlHead.Text = Result.Name;
ltrlHead.Text = ltrlHead.Text + " : " + bALBooks.GetBookTitle(Convert.ToInt32(hdfBookId.Value));
BindData(Convert.ToInt32(hdfBookId.Value), Result.LoginCode);
}
catch (Exception ex)
{
Utility.SaveErrorLog(ex.Message, System.IO.Path.GetFileName(Request.Path), System.Reflection.MethodBase.GetCurrentMethod().Name, Convert.ToInt32(hdfLoginCode.Value));
ShowMessage("Oops...", ex.Message, "error");
}
}
protected void gr_RowDataBound(object sender, GridViewRowEventArgs e)
{
try
{
if (e.Row.RowType != DataControlRowType.DataRow)
return;
e.Row.Cells[0].HorizontalAlign = HorizontalAlign.Center;
for (int i = 8; i < e.Row.Cells.Count - 1; i++)
{
string cellValue = e.Row.Cells[i].Text;
var row = (DataRowView)e.Row.DataItem;
var currentPerson = row[0].ToString();
var currentDate = row.DataView.Table.Columns[i];
var commandArgument = currentPerson + ":" + currentDate;
LinkButton button = new LinkButton();
button.Text = cellValue;
button.CommandName = "Select";
button.CommandArgument = commandArgument;
button.OnClientClick = "GetModuleData(this)";
if (cellValue.ToUpper().Trim() == "A")
{
button.CssClass = "badge badge-danger";
}
}
}
}
Thanks
Mohamed Azarudeen ZPosted May 16, 2023, 4:04 PM
Hi Ramco try this.
Remove the
OnRowCommand="grdPlanning_RowCommand"attribute from the GridView markup. This will detach the event handler from theRowCommandevent.Add the
RowCommandevent handler programmatically in the code-behind file (Page_LoadorOnInitevent). Here's an example:Make sure to replace
Page_Loadwith the appropriate event handler method if you're using a different event.grdPlanning_RowCommandmethod to match the correct delegate signature:Ramco RamcoPosted May 16, 2023, 3:53 PM
Hi Mohammed
protected void grdPlanning_RowCommand(object sender, GridViewCommandEventArgs e)
{
}
Thanks
Mohamed Azarudeen ZPosted May 16, 2023, 3:40 PM
Kindly check this once in your code
Make sure that the method has the
(object sender, GridViewCommandEventArgs e)parameters and that it is declared asprotected. Also, confirm that it is not declared asstaticor has any additional parameters.Hope this resolves the error
Ramco RamcoPosted May 16, 2023, 3:36 PM
Hi Mohammed
It is giving error - No OverLoad for grdPlanning_RowCommand matched delegate eventHandler
Thanks
Mohamed Azarudeen ZPosted May 16, 2023, 3:07 PM
In the provided code, the
RowCommandevent of the GridView is not getting executed because the LinkButton in each row is missing theOnClickevent handler attribute. TheOnClickattribute is necessary for the LinkButton to trigger theRowCommandevent when clicked.To fix this, modify the code inside the
gr_RowDataBoundmethod as follows:With these modifications, the LinkButton will have an
OnClickevent handler that references thegrdPlanning_RowCommandmethod. TheRowCommandevent will be triggered when the LinkButton is clicked, and the code inside thegrdPlanning_RowCommandmethod will execute.Make sure to add these modifications and retest your code. The
RowCommandevent should now be triggered properly.