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. text from DataGrid

text from DataGrid

Scheduled Pinned Locked Moved ASP.NET
help
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.
  • L Offline
    L Offline
    Learner520
    wrote on last edited by
    #1

    hi everybody I have a textbox in Datagrid > and i want to get text from this textbox foreach(DataGridItem xItem in DGUpdateStudents.Items) { clsobj.StudentId = DGUpdateStudents.DataKeyField[xItem.ItemIndex]; clsobj.ForeName=(String) ((TextBox)xItem.FindControl("TxtForeName")).Text; } no error but doesnot return text from textbox like if enter name like John it returns me "" empty strings. thanks in adv for help.

    N 1 Reply Last reply
    0
    • L Learner520

      hi everybody I have a textbox in Datagrid > and i want to get text from this textbox foreach(DataGridItem xItem in DGUpdateStudents.Items) { clsobj.StudentId = DGUpdateStudents.DataKeyField[xItem.ItemIndex]; clsobj.ForeName=(String) ((TextBox)xItem.FindControl("TxtForeName")).Text; } no error but doesnot return text from textbox like if enter name like John it returns me "" empty strings. thanks in adv for help.

      N Offline
      N Offline
      N a v a n e e t h
      wrote on last edited by
      #2

      Are you binding the grid in page_load and binding without checking IsPostBack?

      Learner520 wrote:

      (String) ((TextBox)xItem.FindControl("TxtForeName")).Text;

      This is bad practice. If your item can't be found, this code will crash. First find the control, do NULL checking and ensure you have a valid object before you access Text property on it. :)

      Navaneeth How to use google | Ask smart questions

      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