rai nalasa rai nalasa - 1 year ago 63
ASP.NET (C#) Question

return row number where cell is similar to string

How could I get the row number of my if statement?

private void load_session_value()
string trans_id = Session["transaction_id_report"].ToString();
string trans_number = Session["transaction_no_report"].ToString();

//string grid_value_id = GridView1
//string grid_value_num
if (trans_id != null && trans_number != null)
foreach (GridViewRow row in GridView1.Rows)
if (row.Cells[1].Text.ToString() == trans_id && row.Cells[2].Text.ToString() == trans_number)

row.BackColor = ColorTranslator.FromHtml("#A1DCF2");
//GridView1.SelectedIndex = rowIndex;
GridView1.SelectedIndex = ???

GridView1_SelectedIndexChanged(new object(), new EventArgs());

I need the row number for my
currently the
is getting on the right row. But if possible could I get the
that has the

Answer Source

Just switch your foreach statement with a for statement..

for (int i = 0; i <  GridView1.Rows.Count; i++)
    GridView1.SelectedIndex = i;
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download