Jaya Prakash

Jaya Prakash

  • 547
  • 2.3k
  • 65.4k

How to get Template value from grid?

Mar 7 2024 5:41 AM
<Columns>
 <asp:BoundField DataField="RowNo" HeaderText="S No"/>
  <asp:BoundField DataField="RequestID" HeaderText="RequestID"/>
  <asp:BoundField DataField="AckNo" HeaderText="AckNo"/>
<asp:BoundField DataField="UTR" HeaderText="UTR"/>
<asp:BoundField  DataField="CreatedDate" HeaderText="Created Date"/>
<asp:TemplateField HeaderText="Status">
<ItemTemplate>
 <span  class='text-bold text-<%# Eval("Status").ToString() == "FAILED" ? "red" :  Eval("Status").ToString() == "PENDING"? "yellow" :Eval("Status").ToString() == "SUCCESS" ? "green": Eval("Status").ToString() == "REFUND" ? "orange":"green" %>' style="font-size: 13px;font-weight:bold;"><%# Eval("Status") %></span>
  </ItemTemplate>
 </asp:TemplateField>
</Columns>                                 

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== "&nbsp;")
                    {
                        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 &nbsp; instead of this it should take empty if cell doesn't  contain a value? pls help me 

 


Answers (3)