On Jul 6, 8:00 am, "CJM" <cjmnew...@newsgroup.nospamwrote:
Quote:
[code snippets at the end]
>
I have a page that allows the user to search a DB by querying one of 3
fields. When results are returned, I want the user to be able to click a
value in one of three columns (that directly relate to the 3 searchable
fields) and have the page postback and requery given the selected criterion.
For example, the user searches for retainer #1, which has a Tip Width of 5.
So he clicks on the 5 and it searches again for all retainers that have a
similar Tip Width.
>
To achieve this, I have a Gridview with several BoundFields and one
LinkButton (within a Template) for each of the 3 searcable columns. So far
so good...
>
I'm strugglin however to make the next move. I don't know how to code it so
that by clicking on a LinkButton, the SearchVal field is repopulated with
the selected value, the SearchType radio button is set to the appropriate
type, and the btnSearch_Click sub is called. I'm not sure which event of
which control I need to create a handler for, nor what I do thereafter.
>
I imagine this is quite simple, but it's my first proper ASP.NET
application, so I'm still rather out of my depth. I've searched for
examples, but I haven't found one that matches this scenario, though there
have been plenty of hints that this is a commonly used approach.
>
Can anyone point me in the rifght direction?
First, you need to set the CommandArgument for the button.
Then you need to set a CommandName for the button.
Then in the code behind, you need to capture the RowCommand event for
your Gridview. Your argument will be passed, along with the
commandName. In the codebehind, check to see if it's the proper
commandName (even if you have only 1 command right now, I think it's
good practice to always check, so if you add another command later,
you don't have to recode). Then do your business with populating your
search criteria, setting up your parameters, rebinding, etc.
Hope that gives you an overview.