I am having issue when I select a row after sorting it switches back to row index 0. I would like to able to sort or search and select spesific row. So the data can be sent to my text boxes for updating. Here are my codes.
protected void GridViewSys_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Attributes["onclick"] = Page.ClientScript.GetPostBackClientHyperlink(GridViewSys, "Select$" + e.Row.RowIndex);
e.Row.ToolTip = "Click to select this row.";
}
}
protected void GridViewSys_SelectedIndexChanged(object sender, EventArgs e)
{
foreach (GridViewRow row in GridViewSys.Rows)
{
if (row.RowIndex == GridViewSys.SelectedIndex)
{
row.BackColor = ColorTranslator.FromHtml("#007bff");
row.ToolTip = String.Empty;
String sysName, sysDesc, sysVen, sysReq, sysPO, sysLT, sysSOW, sysSLA, sysComp, sysSQ;
sysName = row.Cells[0].Text;
sysDesc = row.Cells[1].Text;
sysVen = row.Cells[2].Text;
sysReq = row.Cells[3].Text;
sysPO = row.Cells[4].Text;
sysLT = row.Cells[5].Text;
sysSOW = row.Cells[6].Text;
sysSLA = row.Cells[7].Text;
sysComp = row.Cells[8].Text;
sysSQ = row.Cells[9].Text;
txtSysName.Text = sysName;
txtSysDesc.Text = Server.HtmlEncode(sysDesc);
txtSysVen.Text = sysVen;
txtSysReq.Text = sysReq;
txtSysPO.Text = sysPO;
txtSysLT.Text = sysLT;
lblSow.Text = sysSOW;
lblSLA.Text = sysSLA;
lblComp.Text = sysComp;
lblSQ.Text = sysSQ;
}
else
{
row.BackColor = ColorTranslator.FromHtml("#FFFFFF");
row.ToolTip = "Click to select this row.";
}
}
What I have tried:
Looked all over the internet but no luck. Honestly I have no clue how to fix this.