Ramco Ramco

Ramco Ramco

  • 442
  • 3.4k
  • 528.5k

RowCommand not getting executed

May 16 2023 2:09 PM

Hi 

  I have below code but RowCommand not getting executed

<asp:GridView ID="grdPlanning" class="table table-bordered" runat="server" OnRowDataBound="gr_RowDataBound" 
                                            onsorting="grdPlanning_Sorting" AllowSorting="True" OnRowCommand="grdPlanning_RowCommand" AutoGenerateColumns="true" DataKeyNames="BookID" >
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


Answers (5)