DataKeys null only in RowCommand

R

rlm

I have a gridview updating every 5 seconds. There are several DataKeys
declared which I access successfully in the RowDataBound event. However, in
the ROwCommand event the count of the DataKeys array is zero, and the
SelectedDataKey is null.

Shouldn't the DataKeys be available in the RowCommand event? Is anyone else
accessing them there? Can anyone think of any thing I might be doing which
could cause them to be unavailable in RowCommand even though they are
available in RowDataBound?

Any other thoughts how else I might get the database RID for the row that a
button was clicked on, even though the id is not displayed?
 
Joined
Apr 28, 2009
Messages
1
Reaction score
0
RowCommand data field..

You can change the button into a select button by altering its CommandName e.g.:

<asp:ButtonField CommandName="Select" DataTextField="Name" HeaderText="Name"/>

Then you can wire in the SelectedIndexChanged event and get the DataKey value as per in C# code behind:

protected void grdReferralAttachments_SelectedIndexChanged(object sender, EventArgs e)
{
string strValue = Convert.ToString(((System.Web.UI.WebControls.GridView)(sender)).SelectedDataKey.Value);
int intSelectedIndex = ((System.Web.UI.WebControls.GridView)(sender)).SelectedIndex;
}


Andrew Maisey
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,969
Messages
2,570,161
Members
46,705
Latest member
Stefkari24

Latest Threads

Top