开发者

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜