1

I added a checkbox to my list, just like there is a checkbox in a People and Groups list:alt text http://img8.imageshack.us/img8/605/ss20090528093906.png

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)

3 Answers 3

3

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://tqcblog.com/2009/05/04/sharepoint-discussion-with-jquery

Sign up to request clarification or add additional context in comments.

3 Comments

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" ...> added onclick="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.
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.
Thanks, looks like that one died a couple of blog versions ago. Should be working now.
3

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.

Comments

0

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.

1 Comment

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.