Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / DataGrid / February 2004

Tip: Looking for answers? Try searching our database.

use editable row  to set up filter for the underlying dataview

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Ole - 03 Feb 2004 19:48 GMT
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
Earl Teigrob - 04 Feb 2004 21:10 GMT
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

> Hello everybody.
>
[quoted text clipped - 67 lines]
>
> Greetings Ole VM

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.