Welcome Guest
Tanvtech logo
Tanvtech logo
 
In this article we are going to build a search control or application using a Linq ,Gridview and search by LastName.
Add Label, textbox,Gridview and a Button control, it should look like this

Here is the html of the page or the control

and here are the code that you have to write.

Question 2: Search student whom last name contain “as” in
Answer: Modify the click button event with this code
protected void TanvtechButton_Click(object sender, EventArgs e)
{
   using (TanvtechDataClassesDataContext db = new          TanvtechDataClassesDataContext())
{
    var datainfo = db.StudentInfos.ToList().Where(x =>    x.StudentLastName.Contains(TanvtechTextBox.Text)).ToList();    TanvtechGridView.DataSource = datainfo; TanvtechGridView.DataBind();
}
}

Note: Ashraf also start with AS but is missing

This is because it has A as upper case, to fix this update the Datainfo code with
this line var datainfo = db.StudentInfos.ToList().Where(x => x.StudentLastName.ToLower().Contains(TanvtechTextBox.Text.ToLower())).ToList();
 
© Tanvtech. All Rights Reserved.