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. Web Development
  3. ASP.NET
  4. Datagrid item

Datagrid item

Scheduled Pinned Locked Moved ASP.NET
helptutorialquestion
5 Posts 3 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.
  • M Offline
    M Offline
    Morgs Morgan
    wrote on last edited by
    #1

    Hi guys, i have a datagrid, i would like to get the value of one column when user clicks on that row(item) so that i can show the details of that row(item) on the next page. I have tried the below and am not so sure how to proceed:

    protected void available_ItemDataBound(object sender, DataGridItemEventArgs e)
    {
    //string striD;
    foreach(DataGridColumn col in available.Columns)
    {
    if (e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.Item)
    {
    //striD = available.DataKeys[e.Item.ItemIndex].ToString();
    e.Item.Attributes.Add("onmouseover", "this.style.backgroundColor='#F9F9F9' this.style.cursor='pointer';");
    e.Item.Attributes.Add("onmouseout", "this.style.backgroundColor='#ffffff';this.style.cursor='pointer';");

        }
    }
    

    }

    Does anyone know how i can manage to get the value of one column in tha row that has been clicked? Please help me :doh: Regards MS

    N 1 Reply Last reply
    0
    • M Morgs Morgan

      Hi guys, i have a datagrid, i would like to get the value of one column when user clicks on that row(item) so that i can show the details of that row(item) on the next page. I have tried the below and am not so sure how to proceed:

      protected void available_ItemDataBound(object sender, DataGridItemEventArgs e)
      {
      //string striD;
      foreach(DataGridColumn col in available.Columns)
      {
      if (e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.Item)
      {
      //striD = available.DataKeys[e.Item.ItemIndex].ToString();
      e.Item.Attributes.Add("onmouseover", "this.style.backgroundColor='#F9F9F9' this.style.cursor='pointer';");
      e.Item.Attributes.Add("onmouseout", "this.style.backgroundColor='#ffffff';this.style.cursor='pointer';");

          }
      }
      

      }

      Does anyone know how i can manage to get the value of one column in tha row that has been clicked? Please help me :doh: Regards MS

      N Offline
      N Offline
      NeverHeardOfMe
      wrote on last edited by
      #2

      Assuming your DataGrid is bound to a DataView with a unique ID value for each row, include a Hypelink in your DataGrid columns - say hypDetails, maybe within a template column - then you can put in your ItemDatBound code:

      DataRow dr = e.Item.DataItem.Row;
      HyperLink hypDetails = CType(e.Item.FindControl("hypDetails"), HyperLink);
      hypDetails.NavigateUrl = "details.aspx?id=" & CStr(dr("ID"));

      This will pass the ID value of that row as a parameter to the next page (details.aspx)

      M 1 Reply Last reply
      0
      • N NeverHeardOfMe

        Assuming your DataGrid is bound to a DataView with a unique ID value for each row, include a Hypelink in your DataGrid columns - say hypDetails, maybe within a template column - then you can put in your ItemDatBound code:

        DataRow dr = e.Item.DataItem.Row;
        HyperLink hypDetails = CType(e.Item.FindControl("hypDetails"), HyperLink);
        hypDetails.NavigateUrl = "details.aspx?id=" & CStr(dr("ID"));

        This will pass the ID value of that row as a parameter to the next page (details.aspx)

        M Offline
        M Offline
        Morgs Morgan
        wrote on last edited by
        #3

        Thanks alot man, i will give it a try just now.... but unfortunatly 'CType' does not exist in C# only VB...is there an alternative to this? :doh: Regards, MS

        N M 2 Replies Last reply
        0
        • M Morgs Morgan

          Thanks alot man, i will give it a try just now.... but unfortunatly 'CType' does not exist in C# only VB...is there an alternative to this? :doh: Regards, MS

          N Offline
          N Offline
          NeverHeardOfMe
          wrote on last edited by
          #4

          OMG I've been outed! ;-) I'm sure a little Googling will sort you out...

          1 Reply Last reply
          0
          • M Morgs Morgan

            Thanks alot man, i will give it a try just now.... but unfortunatly 'CType' does not exist in C# only VB...is there an alternative to this? :doh: Regards, MS

            M Offline
            M Offline
            m dhu
            wrote on last edited by
            #5

            in c#....

            HyperLink hypDetails = (HyperLink)e.Item.FindControl("hypDetails");

            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