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. How To Fill gridview textbox by selecting data from gridview Dropdownlist

How To Fill gridview textbox by selecting data from gridview Dropdownlist

Scheduled Pinned Locked Moved ASP.NET
tutorial
4 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.
  • V Offline
    V Offline
    vanillaET
    wrote on last edited by
    #1

    I want to fill gridview textbox by selecting data from gridview Dropdownlist

    R C 2 Replies Last reply
    0
    • V vanillaET

      I want to fill gridview textbox by selecting data from gridview Dropdownlist

      R Offline
      R Offline
      raju melveetilpurayil
      wrote on last edited by
      #2

      try like this

      //DropDownList inside the gridview
      protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
      {
      //identifying DropDownList
      DropDownList gridDropDownList = (DropDownList)sender;
      //selecting grid row
      GridViewRow gridRow = (GridViewRow)gridDropDownList.NamingContainer;
      //setting Index
      int selectedIndex = gridRow.DataItemIndex;
      //finding textbox in selected gridview row
      TextBox textBox = (TextBox)GridView1.Rows[selectedIndex].FindControl("yourTextBoxID");
      string selected = gridDropDownList.SelectedValue;
      if (textBox != null)
      {
      textBox.Text = selected;
      }
      }

      My Mind is the Devil's Workshop.

      V 1 Reply Last reply
      0
      • R raju melveetilpurayil

        try like this

        //DropDownList inside the gridview
        protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
        {
        //identifying DropDownList
        DropDownList gridDropDownList = (DropDownList)sender;
        //selecting grid row
        GridViewRow gridRow = (GridViewRow)gridDropDownList.NamingContainer;
        //setting Index
        int selectedIndex = gridRow.DataItemIndex;
        //finding textbox in selected gridview row
        TextBox textBox = (TextBox)GridView1.Rows[selectedIndex].FindControl("yourTextBoxID");
        string selected = gridDropDownList.SelectedValue;
        if (textBox != null)
        {
        textBox.Text = selected;
        }
        }

        My Mind is the Devil's Workshop.

        V Offline
        V Offline
        vanillaET
        wrote on last edited by
        #3

        Dear raju melveetilpurayil, Thanks for your reply. It's useful. :thumbsup:

        1 Reply Last reply
        0
        • V vanillaET

          I want to fill gridview textbox by selecting data from gridview Dropdownlist

          C Offline
          C Offline
          cpsglauco
          wrote on last edited by
          #4

          Hi, I suggest to you a javascript client solution: add this javascript function somewhere in your project

          function selectChoice(ddl, textboxID) {
          var chosenoption = ddl.options[ddl.selectedIndex];
          if (chosenoption.value != 'nothing') {
          document.getElementById(textboxID).value = chosenoption.value;
          }
          }

          add onrowdatabound event for your grid with this code:

          protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
          {
          if (e.Row.RowType == DataControlRowType.DataRow)
          {
          DropDownList ddlChoice = e.Row.FindControl("ddlChoice") as DropDownList;
          TextBox txtSelectedValue = e.Row.FindControl("txtSelectedValue") as TextBox;

              string jScript = "selectChoice(this, '{0}');";
              ddlChoice.Attributes.Add("onchange", string.Format(jScript, txtSelectedValue.ClientID));
          }
          

          }

          ____________________ Web Programmer http://glucolo.wordpress.com

          modified on Monday, July 4, 2011 6:10 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