65.9K
CodeProject is changing. Read more.
Home

ASP.NET using GridView Control as Lookup

starIconstarIconstarIcon
emptyStarIcon
starIcon
emptyStarIcon

3.36/5 (13 votes)

Mar 25, 2007

CPOL
viewsIcon

186695

downloadIcon

2191

ASP.NET using GridView control as lookup

Screenshot - Lookup.jpg

Introduction

This simplifies the way to enter lookup values in a textbox.
I have used GridView to return lookup values for FormView control.

You can use the lookup to return a value to any ASP.NET textbox control.

I have used two lookup pages, lookupSupplier.aspx and lookupCategory.aspx. These two lookup pages work for main page default.aspx page which has FormView control that is used for inserting and editing the Products table.

Background

You must know how the GridView control works.

Using the Code

The following is an example of creating a template column for GridView control.

You need to add an ASP.NET hyperlink control for a template column. This hyperlink will be used to return the value(text) in column one (column index 0) of the GridView control.

<asp:TemplateField>
<ItemTemplate>
<asp:HyperLink ID="hlReturnLookupValue" runat="server">Select</asp:HyperLink>
</ItemTemplate>
</asp:TemplateField>

Points of Interest

Try to use caching for lookup pages so that lookup pages get opened quickly and work fast. However, this is not essential.

History

I will update this page based on your feedback.