<%# Eval("Status") %>
when i filter my grid with Status im getting records

and im looping through the grid to get each row values storing in a string variable and send to database
im trying like this
protected void HitAPI_Click(object sender, EventArgs e)
{
foreach(GridViewRow gridViewRow in Paymentview.Rows)
{
for (int i = 0; i < Paymentview.Columns.Count; i++)
{
if (!String.IsNullOrWhiteSpace(gridViewRow.Cells[2].Text))
{
String RequestID = gridViewRow.Cells[2].Text;
}
if (!String.IsNullOrWhiteSpace(gridViewRow.Cells[3].Text) || gridViewRow.Cells[3].Text== " ")
{
String AckNo = gridViewRow.Cells[3].Text;
}
if (!String.IsNullOrWhiteSpace(gridViewRow.Cells[4].Text))
{
String UTR = gridViewRow.Cells[4].Text;
}
string statusValue = DataBinder.Eval(e.gridViewRow.DataItem, "Status").ToString();
}
}
}
but here im unable to get status value as pending returning null to me how can i get it
and also i keep checks for if cell value is empty is should not take instead of this it should take empty if cell doesn't contain a value? pls help me
Naimish MakwanaPosted Mar 7, 2024, 5:54 AM
In your code, you are trying to access the
Statusvalue from aTemplateFieldin aGridView. However, theTemplateFielddoes not expose its value through theCellscollection like aBoundFielddoes. Instead, you need to find the control in theTemplateFieldand get the value from it.Here’s how you can modify your code to get the
Statusvalue:In this code, I’m using the
FindControlmethod to find theLabelcontrol in theTemplateField. Once the control is found, you can get theTextproperty from it which should give you theStatusvalue.Also, to check if a cell is empty, you can compare the
Textproperty of the cell to , which is the HTML entity for a non-breaking space. This is often used in HTML to represent an empty space. If theTextproperty is equal to you can consider the cell to be empty. In your code, you are already doing this correctly.Thanks
Naimish MakwanaPosted Mar 7, 2024, 7:23 AM
Try this one.
Regarding your second question,
is the HTML entity for a non-breaking space. When you check if a cell’s text is, you’re effectively checking if the cell is empty. If you want to replacewith an empty string, you can do so like this:Thanks.
Jaya PrakashPosted Mar 7, 2024, 7:18 AM
then i should add a label control?
can't we do without adding a label control?