Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Need Explanation on Pass DataKeyNames into Code Behind

Need Explanation on Pass DataKeyNames into Code Behind

Need Explanation on Pass DataKeyNames into Code Behind

I've been struggling in half day to strive for understanding "DatakeyNames" obtained from listview where it passed the Entity fields value captured from "EntityDatasource" and stored into DataKeyNames for later use in Code Behind (Example: 'EntityDataSource1_Deleted' events).

<asp:ListView ID="ListView1" runat="server" DataKeyNames="Id,ImageUrl" DataSourceID="EntityDataSource2" OnItemDeleted="ListView1_ItemDeleted" >

-In My Code Behind,

protected void EntityDataSource2_Deleted(object sender, EntityDataSourceChangedEventArgs e)
string id_ = this.ListView1.DataKeys[0]["Id"].ToString();

string url_ = this.ListView1.DataKeys[0]["ImageUrl"].ToString();

ScriptManager.RegisterStartupScript(this, GetType(), "Notification", "alert('check ID:" + id_ + "with Url:" + url_ + "')", true);

} //End of ItemDeleted

My Question Here:

1. What is structure "[0]" means where it is used besides "DataKeys".

2. If I change "[0]" to be "[1]", it would obtained the same result as taken from "[0]".

3. If I change "[0]" with "[this.listview1.selectedIndex]", it will end up into unlimited looped or hanging in pages postback.Why?

RE: Need Explanation on Pass DataKeyNames into Code Behind

[0] means the first element in an array. This can be used anywhere in your code, etc.
[1] would be the second element. It may not be the same values as [0], and does not refer to [0] in any way. They are 2 different elements
3.) I don't understand what you are saying because you didn't post any code, so I am not sure what is happening.

You code is also wrong in tying to access the DataKeys collection. You would do: string id_ = this.ListView1.DataKeys[0].value;

Have you looked online at all? There is plenty of info out there and examples:

RE: Need Explanation on Pass DataKeyNames into Code Behind


Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close