I am trying to make searchable GridView. it's DataSource is EntityDataSource. I have one textbox and a button. The problem is I need to use Linq to access the data. I don't really have any code yet, because I'm net at Linq and not sure what I'm doing. Can anyone help me?
Asked
Active
Viewed 305 times
0
-
If I am not wrong, On click of button you want to search for the data entered in your textbox from the gridview datasource? – Karthik Ganesan May 05 '14 at 18:40
-
Yes @KarthikGanesan I want to be enter a search item in the textbox, then when the button is clicked the records that match the search box will be displayed in the gridview. – hollyquinn May 05 '14 at 18:47
1 Answers
0
This should help you to get started
protected void Page_Load(object sender, EventArgs e)
{
List<Customer> lstCust = new List<Customer>();
if (!IsPostBack)
{
for (int i = 0; i < 10; i++)
{
Customer c = new Customer();
c.FName = "FistName " + i.ToString();
lstCust.Add(c);
}
Session["Data"] = lstCust;
GridView1.DataSource = lstCust;
GridView1.DataBind();
}
}
protected void Button1_Click(object sender, EventArgs e)
{
string searchText = TextBox1.Text;
List<Customer> lstCustSearch = new List<Customer>();
List<Customer> lstCust = new List<Customer>();
lstCust = Session["Data"] as List<Customer>;
lstCustSearch = (from data in lstCust
where data.FName.Contains(searchText)
select data).ToList();
GridView1.DataSource = lstCustSearch;
GridView1.DataBind();
}
}
public class Customer
{
public string FName { get; set; }
}
sorry for the coding convention. just came up with this sample

Karthik Ganesan
- 4,142
- 2
- 26
- 42