Hi
I have attached image and below is the code . Button getting created on first student Hrithvi but not getting created on Srinithya
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;
// Create a new LinkButton control
LinkButton button = new LinkButton();
button.Text = cellValue;
//button.OnClientClick = "showModalPopup('" + cellValue + "'); return false;"; // assuming there is a JavaScript function named 'showModalPopup' that takes the cell value as a parameter
// Replace the text of the cell with the LinkButton control
e.Row.Cells[i].Controls.Clear();
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() == "D")
{
button.CssClass = "badge badge-success";
}
else if (row[i].ToString().ToUpper() == "S")
{
button.CssClass = "badge badge-info";
}
else if (row[i].ToString().ToUpper() == "HB")
{
button.CssClass = "badge badge-primary";
}
e.Row.Cells[i].Controls.Add(button);
}
}
}

Ramco RamcoPosted May 9, 2023, 2:11 PM
Hi Mohammed
On second student CssClass not getting implmented
Thanks
Aravind GovindarajPosted May 9, 2023, 12:05 PM
could you please navigate to the developer tool and check is this CSS style sheet works("badge badge-danger"), on top of that please check is this style applied to your html page .
Mohamed Azarudeen ZPosted May 9, 2023, 12:04 PM
The loop appears to start at index 8, which may not be the appropriate column index for the data, and this appears to be the problem with the code. Additionally, only if the condition is true—which might not be the case for the second row—is the button added. Try changing the code as follows:
Give it a try hope this fixes.