by Jim
Dec 03, 2007 8:39 AM
In the RowDeleting handler for my GridView, the GridViewDeleteEventArgs.Keys collection is empty. I'm setting the DataKeyNames property correctly - what gives?
I found a number of posts about this issue - the DataKeys are populated by the DataBind() but don't seem to survive postback. But they do survive the postback - they just aren't passed
into the GridViewDeleteEventArgs. The keys are still in the GridView itself after postback.
So instead of this:
int ID = int.Parse(((DictionaryEntry)e.Keys[e.RowIndex]).Value.ToString());
I just do this:
int ID = (int)gvSessions.DataKeys[e.RowIndex].Value;
I saw a couple of suggestions to re-bind the data right before doing the delete. This of course ignores the possibility that the data has changed. The wrong record could wind up being deleted, if you're just going by index in the GridView.
by Jim
Dec 02, 2007 2:48 PM
I'm experimenting with the facebook API lately using Nikhil Kothari's Facebook.NET. The first thing I've had to do that wasn't entirely obvious from the example code was update the profile outside the context of a request.
This is a common scenario, I think - sending messages or updating the profile in response to events that happen when nobody is actually accessing the application.
First you need to have stored the facebook ID and infinite session key for the user whose information you want to update. The application key and secret are already in web.config, if you're set up the same way as the example project. So here's the code:
using Facebook.Service;
using Facebook.Web;
using Facebook.Web.Configuration;
namespace MyNamespace.Facebook
{
public class Utils
{
public static void UpdateProfile(string facebookID, string facebookSession)
{
FacebookSection section =
(FacebookSection)ConfigurationManager.GetSection("facebook");
FacebookService service = new FacebookService(
section.Applications[0].ApiKey,
section.Applications[0].Secret,
facebookSession,
facebookID
);
string profileFbml = BuildProfileFbml(facebookID);
service.Profile.SetFbml(profileFbml, null);
string titleFbml = " is testing stuff...";
string bodyFbml = "test";
service.Feed.PublishMiniFeedStory(titleFbml, bodyFbml, null);
}