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?
<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?