Hi
RowCommand not working
protected void grdPlanning_RowCommand(object sender, GridViewCommandEventArgs e)
{
try
{
if (e.CommandName == "Select")
{
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;
TextBox txtSessionDate = (TextBox)e.Row.FindControl("txtSessionDate");
string Remark = DataBinder.Eval(e.Row.DataItem, "Remarks").ToString(); // Replace "ColumnName" with the actual name of your column
if (Remark == "Done" || Remark == "Scheduled")
{
txtSessionDate.Enabled = false;
}
if (Remark == "Deleted")
{
e.Row.Visible = false;
}
for (int i = init+1; i< e.Row.Cells.Count-1; i++)
{
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 = row[i].ToString();
button.CommandName = "Select";
button.CommandArgument = commandArgument;
button.OnClientClick = "GetModuleData(this)";
if (row[i].ToString().ToUpper() == "A")
{
button.CssClass = "badge badge-danger";
}
else if (row[i].ToString().ToUpper() == "B")
{
button.CssClass = "badge badge-warning";
}
else if (row[i].ToString().ToUpper() == "ND")
{
button.CssClass = "badge badge-secondary";
button.OnClientClick = "return false;";
}
else if (row[i].ToString().ToUpper() == "HB")
{
button.CssClass = "badge badge-primary";
}
e.Row.Cells[i].Controls.Add(button);
e.Row.Cells[i].HorizontalAlign = HorizontalAlign.Center;
}
}
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");
}
}
Thanks
Ramco RamcoPosted May 8, 2023, 7:35 AM
Hi RajKiran
I have already defined OnRowCommand="grdPlanning_RowCommand"
Thanks
Rajkiran SwainPosted May 8, 2023, 7:20 AM
It looks like you have defined the `gr_RowDataBound` event handler instead of `grdPlanning_RowCommand` event handler for your `GridView` control. Please make sure that the `OnRowCommand` property of the `GridView` control is set to "grdPlanning_RowCommand".
Also, make sure that you have set the `CommandName` property of the LinkButton in the `gr_RowDataBound` method to "Select" as you have used "Select" command name in the `grdPlanning_RowCommand` method to check for the command name.
If the above suggestions do not resolve the issue, please provide more details on what exactly is not working in the `RowCommand` event.