ASP GridView List
If I wanted to add a new item to a <List>
with the Data key name from a gridview how would I go about doing it?
Example.
List<myClass> myList = new List<myClass>();
myList.add(new myClass(*//The value o开发者_JS百科f the data key name that has been clicked*));
A user might click on another item so it would be repeated etc etc.
@Brian: Check it out:
protected void dataGridView1_SelectedIndexChanging(object sender, GridViewSelectEventArgs e)
{
if(myList == null)
myList = new List<myClass>();
foreach (object keys in dataGridView1.DataKeys[e.NewSelectedIndex].Values)
{
myList.Add(keys);
}
}
You have to do this in rowSelected, and get the data key in a form of:
protected void Gridview_SelectedIndexChanged(..)
{
GridViewRow row = CustomersGridView.SelectedRow;
var key = this.gvw.DataKeys[row.RowIndex].Value;
}
Forget the exact syntax, but this is essentially what you do.
精彩评论