Hey Morten!
the DataKeyNames property is set to the primary key field in the datasource
And also:
When selecting a row in the GridView, the SelectedIndexChanged event isn't
triggered. The row I clicked on isn't marked as selected. I have enabled
selection on the GridView
So the SelectedIndexChanged event I sent in the previous post isn't executed
everytime...
Any suggestions?
"Morten Wennevik" <Mo************@hotmail.comwrote in message
news:op***************@tr024.bouvet.no...
Hi Jeff,
Either SelectedDataKey is null or gvQuestions is null. Seeing that this
is an event method for gvQuestions I would assume SelectedDataKey ==
null. The documentations indicate that this will happen if no row is
selected, or possibly that DataKeyNames is not set.
On Wed, 06 Sep 2006 14:26:52 +0200, Jeff
<it_consultant1@NO_SPAM.hotmail.comwrote:
Hey
asp.net 2.0
The line "int selectedID =
Convert.ToInt32(gvQuestions.SelectedDataKey.Value. ToString());" in the
code
below gives an NullReferenceException (Object reference not set to an
instance of an object.)
protected void gvQuestions_SelectedIndexChanged(object sender, EventArgs
e)
{
try
{
int selectedID =
Convert.ToInt32(gvQuestions.SelectedDataKey.Value. ToString());
if (Request.QueryString["question"] == null)
{
Response.Redirect(Request.Url.ToString() + "?id=" +
selectedID.ToString());
}
else
{
}
}
catch (Exception exception)
{
System.Diagnostics.Debug.WriteLine(exception.Messa ge.ToString());
}
}
Any ideas what I'm doing wrong here?
--
Happy Coding!
Morten Wennevik [C# MVP]