ButtonColumn
-
Hi! I'm pretty new to C#, but, i wanna learn... I have a question... i have a datagridview binded to a database, but i wanted to add also a delete column to erase that row. The problem is i can't find an event to trigger when i push the delete button. this would be the first part of the problem. the second problem is how do i know which row to delete when the button of one raw is pressed?(i would be regardful if u gave me some code examples, too).:-D
-
Hi! I'm pretty new to C#, but, i wanna learn... I have a question... i have a datagridview binded to a database, but i wanted to add also a delete column to erase that row. The problem is i can't find an event to trigger when i push the delete button. this would be the first part of the problem. the second problem is how do i know which row to delete when the button of one raw is pressed?(i would be regardful if u gave me some code examples, too).:-D
Hi, First of all, are you using asp.net or windows? If it is windows you can use the code below: private void dataGrid1_Click(object sender, System.EventArgs e) { DataTable dt = dataGrid1.DataSource as DataTable; if(dt!=null) { string firstField = (dt.Rows[dataGrid1.CurrentRowIndex][0].ToString()); } } As you can see, what I'm doing is casting the datasource datagrid's property to a datatable object. Then using the CurrentRowIndex property I can obtain any field's values from the datatable. If it is an asp.net application, then you can use the code below: private void DataGrid1_ItemCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e) { if(e.CommandName=="Select") { string id = e.Item.Cells[1].Text; Response.Write(id); } } In this case, I'm assuming the ID of the row is presented in the second column (since the first one is the SELECT link). I created a tutorial about GridView control (asp.net 2.0) at www.KYNOU.com. I'm always in this website's chat room. If you want to chat with me live logon to it. I hope I helped :)