views:

1017

answers:

3

I added a checkbox to my list, just like there is a checkbox in a People and Groups list:alt text

However in my list I want to save the selected value to database. But I have no idea how. I was figuring i could add javascript to onClick event, but neither I know where do I put that javascript (or can I use C# code?), neither I have an idea how update a database from javascript.

Maybe you could help me, please? What are the other options? And how would I implement one?

Thank you!

In case if someone else wants to add checkbox, then this article did help me (but it is not detailed one)

A: 

Hi,

you could implement an ItemEventReceiver that does the database stuff for you and attach it to your list. The ItemEventReceiver should listen onto the ItemAdded, ItemUpdated and ItemDeleted event so you can react on these different situations and write the information into your database.

For more information about event receivers you should have a look at Brian Wilson's blog posts about that topic or at MSDN.

Flo
This approach would work, but it defeats my purpose as I don't want to use checkbox in a waywhere user needs to open a form, set a value and click ok. In my case no events are fired. But my purpose for checkbox is for meeting workspace to check those users who are at the meeting. I can use this checkbox even in Web part and that's the goal - check the box in web part and save data to DB
Janis Veinbergs
+3  A: 

Use jQuery and the SharePoint web services - attach a click handler to the checkboxes and include code that finds the item id from the same row - easy enough to locate in firebug.

There's some sample code for the web service part on my blog:

http://www.tqcblog.com/archive/2009/05/04/sharepoint-discussion-with-jquery.aspx

Tom Clarkson
Umm, but is it possible to do it server side? Client clicks checbox, I call a C# script which then updates item?I converted my view to XSLT, to <input type="checkbox" ...>addedonclick="checkboxClicked" and a script <script type="text/C#" runat="server"> private void checkboxClicked(object sender, EventArgs e) { }</script>however it won't work, saying "checboxClick" is undefined.
Janis Veinbergs
Several issues there - input is a client side html element, onclick is a client side event, script blocks are most likely disabled.You can try using an asp.net checkbox tag in there, but I suspect the xsl processing happens after asp.net tag processing.
Tom Clarkson
+3  A: 

YOu could use jQuery, add a click event to all checkboxes with jQuery, and have the click event perform an AJAX call to webservice you write and deploy to Sharepoint. You can use the Content Editor Webpart to inject Javascript in the page. Deploy the webservice as a feature.

Colin