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. GridView with javascript calender

GridView with javascript calender

Scheduled Pinned Locked Moved ASP.NET
javascriptsysadmin
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.
  • A Offline
    A Offline
    AS 13
    wrote on last edited by
    #1

    Hello everybody, I have a gridview where a textbox column is present.I have another column which contain a javascript calender. My gridview is dynamically generated. I want to assign the textbox value through the calender. My gridview code is as below CellSpacing="2" CssClass="text" ForeColor="#333333" GridLines="None" PageSize="4" Width="600px" OnRowDataBound="GrdSubs_RowDataBound"> ForeColor="#333333" /> runat="server" type="checkbox" />

    D 1 Reply Last reply
    0
    • A AS 13

      Hello everybody, I have a gridview where a textbox column is present.I have another column which contain a javascript calender. My gridview is dynamically generated. I want to assign the textbox value through the calender. My gridview code is as below CellSpacing="2" CssClass="text" ForeColor="#333333" GridLines="None" PageSize="4" Width="600px" OnRowDataBound="GrdSubs_RowDataBound"> ForeColor="#333333" /> runat="server" type="checkbox" />

      D Offline
      D Offline
      Declan Bright
      wrote on last edited by
      #2

      When a textbox column of a GridView is written out to the browser, the Id's of the text boxes are generated automatically by ASP.NET. The solution to your problem is letting the javascript calendar know the id of the textbox sitting next to it, in the same row of the grid. You can do this in the RowDataBound event of the GridView which is fired as the data for each row of the GridView is bound.

      protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
      {
      if (e.Row.RowType == DataControlRowType.DataRow)
      {
      // Access textbox here and assign onclick ...
      }
      }

      Once you access the TextBox you can assign the onclick event to it with the appropriate client side textbox Id.

      myTextBox.Attributes\["onclick"\] = "popUpCalendar(this, " + myTextBox.ClientId + ", \\"dd/mm/yyyy\\")";
      

      Use the ClientId property on the server side to get the id of the textbox which will be written to the browser for that particular row. By examining the source of the web page you will see that the onclick for each row will have the correct id for the associated textbox.

      Declan Bright www.declanbright.com

      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