rai nalasa rai nalasa - 6 days ago 6
ASP.NET (C#) Question

Trigger GridView1_SelectedIndexChanged event in pageload if session is == to column

I am trying to use selectedindex on my gridview if it has a column with an == value to session.

Right now I am only successfull on changing its background color. But how could I also trigger the button If it has similar value on my Session.

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_SelectedIndexChanged(new object(),new EventArgs());
}
}
}
}


This is my current output during
page_load


enter image description here

Answer

I'm not sure, but i think you are looking for this.

if (row.Cells[1].Text.ToString() == trans_id && row.Cells[2].Text.ToString() == trans_number)
{
    row.BackColor = ColorTranslator.FromHtml("#A1DCF2");

    //call the Button1_Click method
    Button1_Click(new object(), new EventArgs());
}


protected void Button1_Click(object sender, EventArgs e)
{
    //do the button click stuff
}
Comments