Click here to Skip to main content
15,896,201 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
after filtering values in gridview its not working correctly..
i hav used follwin code.....

protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
{
int selectedrow = Convert.ToInt32(GridView1.SelectedRow.Cells[1].Text.ToString());
}

////cell[1] m taking JOb_ID
its working fine with the first time i binddata() to grid....
but wen i use filtering===>>>>


protected void txttitle_TextChanged(object sender, EventArgs e)
{
string str = txttitle.Text;
da = new SqlDataAdapter("SELECT job_id, jobtitle FROM Job_Details WHERE (jobtitle LIKE '" + str + "%')", con);
DataTable dt = new DataTable();
dt.Clear();
da.Fill(dt);
GridView1.DataSource = dt;
GridView1.DataBind();
}

than if i select any row from gridview its not working and giving firstrow value
Posted

1 solution

There is SO much wrong with this code.


wrote:
string str = txttitle.Text;
da = new SqlDataAdapter("SELECT job_id, jobtitle FROM Job_Details WHERE (jobtitle LIKE '" + str + "%')", con);


This code means any user can erase your database, and probably guess how to add users, remove them, etc. Please tell me that your stream of questions relates to something you're writing for fun, and not something anyone is paying for ?

And no, I don't care if you one vote me for giving real advice and telling the truth.

wrote:
protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
{
int selectedrow = Convert.ToInt32(GridView1.SelectedRow.Cells[1].Text.ToString());
}



You do a postback whenever the selection changes, or the text changes ? Really ? This code is useless. It can't ever 'work' if by work you mean anything other than 'assign an integer that is never used and move on'. So you store an int called selectedRow. Why do you expect that to do ANYTHING for you ?
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900