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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. Web Development
  3. ASP.NET
  4. Getting a reference to a control on GridView RowEditing event

Getting a reference to a control on GridView RowEditing event

Scheduled Pinned Locked Moved ASP.NET
questionjavascriptsysadmindocker
5 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.
  • J Offline
    J Offline
    johland
    wrote on last edited by
    #1

    hi i'm trying to get a reference to a control on GridView RowEditing event: code behind:

    protected void gvChores_RowEditing(object sender, GridViewEditEventArgs e)
    {TextBox txtEditMsg = (TextBox)gvChores.Rows[e.NewEditIndex].FindControl("txtEditMsg");}

    javascript:

    <asp:TemplateField HeaderText="Chore">
    <EditItemTemplate>
    <asp:TextBox runat="server" ID="txtEditMsg" Text='<%# DataBinder.Eval(Container.DataItem,"Chore_contents") %>'/>
    </EditItemTemplate>
    </asp:TemplateField>

    i can't get the reference (returns null) can anyone advice what i'm doing wrong and how can i get the reference to the control? thanks in advance

    T 1 Reply Last reply
    0
    • J johland

      hi i'm trying to get a reference to a control on GridView RowEditing event: code behind:

      protected void gvChores_RowEditing(object sender, GridViewEditEventArgs e)
      {TextBox txtEditMsg = (TextBox)gvChores.Rows[e.NewEditIndex].FindControl("txtEditMsg");}

      javascript:

      <asp:TemplateField HeaderText="Chore">
      <EditItemTemplate>
      <asp:TextBox runat="server" ID="txtEditMsg" Text='<%# DataBinder.Eval(Container.DataItem,"Chore_contents") %>'/>
      </EditItemTemplate>
      </asp:TemplateField>

      i can't get the reference (returns null) can anyone advice what i'm doing wrong and how can i get the reference to the control? thanks in advance

      T Offline
      T Offline
      thomasa
      wrote on last edited by
      #2

      try:

      protected void gvChores_RowEditing(object sender, GridViewEditEventArgs e)
      {
      TextBox txtEditMsg = (TextBox)e.Item.FindControl("txtEditMsg");
      }

      remember that the DataRowView is:

      System.Data.DataRowView drv = (System.Data.DataRowView)e.Item.DataItem;

      Hope it helps Thomas

      J 1 Reply Last reply
      0
      • T thomasa

        try:

        protected void gvChores_RowEditing(object sender, GridViewEditEventArgs e)
        {
        TextBox txtEditMsg = (TextBox)e.Item.FindControl("txtEditMsg");
        }

        remember that the DataRowView is:

        System.Data.DataRowView drv = (System.Data.DataRowView)e.Item.DataItem;

        Hope it helps Thomas

        J Offline
        J Offline
        johland
        wrote on last edited by
        #3

        Thanks Thomas, but the GridViewEditEventArgs does'nt contain a definition for 'Item'..

        T 1 Reply Last reply
        0
        • J johland

          Thanks Thomas, but the GridViewEditEventArgs does'nt contain a definition for 'Item'..

          T Offline
          T Offline
          thomasa
          wrote on last edited by
          #4

          Sorry, I was thinking about DataGrid not a GridView. It seems to me that you are trying to uppdate the row, hens the

          Text='<%# DataBinder.Eval(Container.DataItem,"Chore_contents") %>'/>

          So you should use:

          protected void gvChores_RowUpdating(object sender, GridViewUpdateEventArgs e)
          {
          GridViewRow row = gvChores.Rows[e.RowIndex];
          TextBox txtEditMsg = (TextBox)row.FindControl("txtEditMsg");
          }

          Becouse RowEditing works like this:

          protected void gvChores_RowEditing(object sender, GridViewEditEventArgs e)
          {
          //Set the edit index.
          gvChores.EditIndex = e.NewEditIndex;
          //Bind data to the GridView control.
          BindData();
          }

          To be honest, I have never used GridView since I always use DataGrid, so I might be wrong.

          modified on Thursday, October 2, 2008 6:09 AM

          J 1 Reply Last reply
          0
          • T thomasa

            Sorry, I was thinking about DataGrid not a GridView. It seems to me that you are trying to uppdate the row, hens the

            Text='<%# DataBinder.Eval(Container.DataItem,"Chore_contents") %>'/>

            So you should use:

            protected void gvChores_RowUpdating(object sender, GridViewUpdateEventArgs e)
            {
            GridViewRow row = gvChores.Rows[e.RowIndex];
            TextBox txtEditMsg = (TextBox)row.FindControl("txtEditMsg");
            }

            Becouse RowEditing works like this:

            protected void gvChores_RowEditing(object sender, GridViewEditEventArgs e)
            {
            //Set the edit index.
            gvChores.EditIndex = e.NewEditIndex;
            //Bind data to the GridView control.
            BindData();
            }

            To be honest, I have never used GridView since I always use DataGrid, so I might be wrong.

            modified on Thursday, October 2, 2008 6:09 AM

            J Offline
            J Offline
            johland
            wrote on last edited by
            #5

            thanks. previous comment wasn't relevant... i missed that you've handled RowUpdating event. thanks for your help

            modified on Thursday, October 2, 2008 6:56 AM

            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