I just want to capture a double click!

Today has been a bit of a waste of time.

What I am trying to do is simple enough, yet it seems that I can’t do it.

I have a Datagrid in an ASP.NET form, I want users to be able to click on it and then I want stuff to happen.

Should be pretty easy I thought, until I discovered that there is no DoubleClick event in ASP.

Ok so you can add one in, but not if you let the program build your datagrid for you, only if you specify the column names in HTML. So I added in some crap like:

{Columns}

{asp:TemplateColumn HeaderText=”JobName”}

{ItemTemplate}

{asp:Label ID=”lblJobName” Text='{%# DataBinder.Eval(Container.DataItem, “JobName”) %}’ Runat=server /}

{/ItemTemplate}

{/asp:TemplateColumn}

And the datagrid was able to bind itself like it used to except for one thing… My ability to sort by clicking on the column header was gone! I have no idea why, sorting was still enabled and I had an onSortCommand thing in there, but they became unclickable. I could put a separate sort command field in each template column, but then it wouldn’t use my custom sort. Infuriating, but not what this post is actually about.

So anyway, I managed to put some code in the ItemDataBound declaration of the datagrid that looked for my column labels that I created as explained above and added an OnDblClick event to each {TR} in the datagrid.

The datagrid now knows when I double click on it!

The problem in, I can’t get it to do anything once I do, unless I write the function in Javascript and stick it on the page with the HTML, which I REALLY don’t want to do. I can’t get it to see a function in the code behind, even though the datagrid sort command lives there and that can be found just fine. It won’t recognise anything I put in there, it just says Unknown Object.

It would be alright if all I wanted to do was a little Javascript function, like a pop-up box with the name of the row that was clicked on or something, but I need to write to a file and already have a function for that sitting in the VB part.

So the good news is I am able to handle a double-click event. The bad news is that I can’t also have a bi-directional sort and whatever function I want the double click to call has to be in Javascript. Ggaaahh!

So I spent half the day trying to find a good solution to my double clicking problem and I haven’t found one. I guess I’ll have to put a checkbox column in or something, which I don’t want to do cause it’s a wide grid already and being any wider will make its layout look lousy.

Ok, I have worked out what I am going to do. I’ll put in a textbox and a button and the user will have to put the name of the item in the textbox then click to perform the action. I don’t know how I’m going to squish it in, but that is another problem. I probably would have done something like this in the first place if I had have designed the stuff myself, instead of adapting an already existing application and converting it into a web page.

Advertisements
This entry was posted in Uncategorized. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s