Basically, I have a table (GridView) on an aspx page whose data is defined by TemplateFields. For example:
<asp:GridView runat="server" ID="grdProdutos">
<Columns>
<asp:TemplateField HeaderText="Produto">
<ItemTemplate>
<asp:Label runat="server" ID="lblProduto" Text='<%# Eval("NomeProduto")%>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Tipo">
<ItemTemplate>
<asp:Label runat="server" ID="lblTipo" Text='<%# Eval("TipoProduto")%>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Preço">
<ItemTemplate>
<asp:Label runat="server" ID="lblPreco" Text='<%# Eval("PrecoProduto")%>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
The methods used in code behind are as follows:
RepositorioProdutos banco = new RepositorioProdutos();
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
CarregarGridView();
}
}
public void CarregarGridView()
{
var produtos = banco.ObterProdutos();
if (produtos != null)
{
grdProdutos.DataSource = produtos;
grdProdutos.DataBind();
}
else
{
throw new Exception("Nenhum produto encontrado.");
}
}
I would like to know how I could implement a product search (looking for a term in any field) and how I could implement a sort order by clicking the column name I'd like to sort (like in Windows Explorer), without needing (ie without having to access the banco.ObterProdutos()
method again).
Note: For the search, I'm considering using a textBox that will be used to enter the search keyword, and a button that will trigger the search.