use editable row to set up filter for the underlying dataview

O

Ole

Hello everybody.

Problem:

I want to use a row in the datagrid, that is the first row.
This row should be allways blank, so that the user can enter
a value in _one_ column. This value should be used as the
filter criteria for that row.

example:
| header01 | header02 | header03 |
----------------------------------
| | | | <- this row should consist of textinputfields
----------------------------------
| cat01 | data | data |
----------------------------------
| cat01 | data | data |
----------------------------------
| cat02 | data | data |
----------------------------------

if now the user enters the following:

| header01 | header02 | header03 |
----------------------------------
| "cat01" | | | <- user enters filter criteria and presses
---------------------------------- enter
| cat01 | data | data |
----------------------------------
| cat01 | data | data |
----------------------------------
| cat02 | data | data |
----------------------------------

The datagrid now should be set up with the filter criteria for the column
in that the user entered the value. Meaning concretely, that the
first row should only show the values of "group" cat01.

How is this possible ?

I tried to insert a datarow at top of the datatable that is the datasource for
the datagrid. Then i set up this very row to be editable all the time.

How can i trap the event triggered when the user presses enter in the text box ?

code looks something like this : ( all code is pseudonyms )

(asp:datagrid id="_dg_main" runat="server"
OnItemUpdateCommand="_dg_main_UpdateCommand")
...
(/asp:datagrid)

( replaced tags with parens, google terms )

In the codebehind file i wrote this:

....

public void _dg_main_UpdateCommand ( Object sender, ... e ) {
DataTable dt = get_datasource ( );
filtercrit = e.Item.Cells .. ( get cell content ) .. ;
DataView view = new DataView ( dt );
view.filter = filtercrit ( or something like this )
}

again, how may i map the pressing of the enter key within a text box
to firing the event ?

Thanks in advance for any hints and excuse my bad english.

Greetings Ole VM
 
E

Earl Teigrob

I like you idea. I have always done the same thing with fields above the
datagrid but this is certainly more intuative. Getting an event to fire when
you press enter in a text box is not a supported event in for the normal
TextBox control. I believe you will need to create a custom control that
trap the OnKeyPress event and generate a postback based on this event(when
the enter key is pressed). If this is the case, it will take a bit of work.
The JS to trap keystrokes looks like this:

<form>
<input type="text" value="abc" name="test" onkeypress="captureKey(event);">
</form>
<script>
function captureKey(e) {
var key;
if (e && e.which) {
key = e.which;
} else if (window.event && window.event.keyCode) { key =
window.event.keyCode;
} alert(key);
}
</script>

You can read about creating custom controls in any book on the subject but I
like Professional ASP.NET Server Controls for a beginner in this area. The
MS Press book (Developing Microsoft ASP.NET Server Controls and Components )
is much more indepth but too deap for starting IHO. (theres still stuff in
it that is over my head)

I created a custom control for use in dyanamic menus that traps the
onmouseclick event of a <tr> tag and generates a postback. Very Useful!

Earl
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top