Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. ButtonColumn

ButtonColumn

Scheduled Pinned Locked Moved C#
questiondatabasecsharphelp
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    drc_no1
    wrote on last edited by
    #1

    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

    O 1 Reply Last reply
    0
    • D drc_no1

      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

      O Offline
      O Offline
      OmegaCD
      wrote on last edited by
      #2

      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 :)

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups