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. Trigger CommandName=Edit/Select from DropDownList in GridView

Trigger CommandName=Edit/Select from DropDownList in GridView

Scheduled Pinned Locked Moved ASP.NET
questiondatabasehelptutorial
7 Posts 4 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.
  • I Offline
    I Offline
    irfankhan5
    wrote on last edited by
    #1

    Alright, here’s what I want to do. I have a GridView with columns say EmployeeID, FirstName, LastName, and Department. Now, I want to add an additional column with the DropDownList. The list has the options of Select Edit Delete ( I know how to do this one) Now, if the user selects “Edit” or “Select”, I want that row to open up in a DetailsView either as read only or in editable mode depending on what the user selected. I am able to call the select commandname using a linkbutton. However, how do I call it using a dropdownlist? Also, how do I call it directly in editable form in a DetailsView from the dropdownlist? Thanks in advance for all the help and guidance.

    V M R 3 Replies Last reply
    0
    • I irfankhan5

      Alright, here’s what I want to do. I have a GridView with columns say EmployeeID, FirstName, LastName, and Department. Now, I want to add an additional column with the DropDownList. The list has the options of Select Edit Delete ( I know how to do this one) Now, if the user selects “Edit” or “Select”, I want that row to open up in a DetailsView either as read only or in editable mode depending on what the user selected. I am able to call the select commandname using a linkbutton. However, how do I call it using a dropdownlist? Also, how do I call it directly in editable form in a DetailsView from the dropdownlist? Thanks in advance for all the help and guidance.

      V Offline
      V Offline
      VenkataRamana Gali
      wrote on last edited by
      #2

      In this case my sujjestion is take the selectedvalue of dropdownlist, let us assume 1 for select, 2 for edit, 3 for delete. go to selectedIndexChanged event there capture selectedvalue(or SelectedText), based on this call. take the DetailsView columns as hyperlink column, set the URLFormat string & submit the page ..... Thanks Ramana

      I 1 Reply Last reply
      0
      • V VenkataRamana Gali

        In this case my sujjestion is take the selectedvalue of dropdownlist, let us assume 1 for select, 2 for edit, 3 for delete. go to selectedIndexChanged event there capture selectedvalue(or SelectedText), based on this call. take the DetailsView columns as hyperlink column, set the URLFormat string & submit the page ..... Thanks Ramana

        I Offline
        I Offline
        irfankhan5
        wrote on last edited by
        #3

        Sounds good. However, is URL the only way out? Also, how do I know which Employee ID was the SelectedIndexChanged trigerred for? Irfan

        V 1 Reply Last reply
        0
        • I irfankhan5

          Sounds good. However, is URL the only way out? Also, how do I know which Employee ID was the SelectedIndexChanged trigerred for? Irfan

          V Offline
          V Offline
          VenkataRamana Gali
          wrote on last edited by
          #4

          Yes, URL only one way, B'Cas this data exists in Grid, so grid hyperlink column will supports only URL,URLField,URLForamtString props. Finding of Employee ID is through EventArguments object e, try it u will get idea regards GV Ramana

          I 1 Reply Last reply
          0
          • V VenkataRamana Gali

            Yes, URL only one way, B'Cas this data exists in Grid, so grid hyperlink column will supports only URL,URLField,URLForamtString props. Finding of Employee ID is through EventArguments object e, try it u will get idea regards GV Ramana

            I Offline
            I Offline
            irfankhan5
            wrote on last edited by
            #5

            Hi Ramana, Thanks for the help. However, I will have to bug you a bit more. Unfortunately, I am unable to figure out on how to get the Employee ID from e. Since the DropDownList is going to be inside the TemplateField in GridView, I can't even see it in my .cs file. Hence, am unable to see what all I can do with e. Sorry for the trouble. With best wishes, Irfi

            1 Reply Last reply
            0
            • I irfankhan5

              Alright, here’s what I want to do. I have a GridView with columns say EmployeeID, FirstName, LastName, and Department. Now, I want to add an additional column with the DropDownList. The list has the options of Select Edit Delete ( I know how to do this one) Now, if the user selects “Edit” or “Select”, I want that row to open up in a DetailsView either as read only or in editable mode depending on what the user selected. I am able to call the select commandname using a linkbutton. However, how do I call it using a dropdownlist? Also, how do I call it directly in editable form in a DetailsView from the dropdownlist? Thanks in advance for all the help and guidance.

              M Offline
              M Offline
              minhpc_bk
              wrote on last edited by
              #6

              Hi there, Because the SelectedIndexChanged event does not bubble up to the ItemCommand event of the GridView control like the Click event of the LinkButton, so you can create an event handler for the SelectedIndexChanged event of the dropdownlist to get the command name. Depending on what value the user selects, you can open up the DetailsView control either in read-only or editable mode by setting the DefaultMode property to ReadOnly or Edit accordingly. To get the value EmployeeID of the selected row, you might consider the two options below: + You can get from the column that the EmployeeID field is bound to. + You can save and get this values in the DataKeys collection of the GridView control by specifying the DataKeyNames property. To access the currently selected row from the event handler of SelectedIndexChanged event, you simply get the naming container of the dropdownlist since it is placed in the template field. The sample looks like this:

              protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
              {
              DropDownList DropDownList1 = sender as DropDownList;
              GridViewRow GridViewRow1 = DropDownList1.NamingContainer as GridViewRow;

              ....
              

              }

              1 Reply Last reply
              0
              • I irfankhan5

                Alright, here’s what I want to do. I have a GridView with columns say EmployeeID, FirstName, LastName, and Department. Now, I want to add an additional column with the DropDownList. The list has the options of Select Edit Delete ( I know how to do this one) Now, if the user selects “Edit” or “Select”, I want that row to open up in a DetailsView either as read only or in editable mode depending on what the user selected. I am able to call the select commandname using a linkbutton. However, how do I call it using a dropdownlist? Also, how do I call it directly in editable form in a DetailsView from the dropdownlist? Thanks in advance for all the help and guidance.

                R Offline
                R Offline
                ricardojb
                wrote on last edited by
                #7

                Alright, this can get a little tricky. Option 1, use buttons or links. You just can add a Select column or just use the smart tag and check the Enable Selection checkbox and the IDE will add the column for you. Then, your detailsview will have to take the value of EmployeeId from the GridView, to do that you have to add EmployeeId to the DataKeyNames collection of the gridview (so the selected value will be the employeeid). Now, this IS tricky, because depending on the datasource your are using, the DetailsView will try to get the data, so you either will have to select one row in the GridView when you load the page or set the default value of the SelectParameter in the DetailsView's DataSource so it will return nothing if nothing is selected. (hope I've been clear) Then your details view could handle the other operations. If you must use a dropdown, then you will have to do everything in code, that is detect which selection was made and then get the data for the DetailsView and explicitly bind it. You will have to do two additionals things. First, you will have the AutoPostBack property of the dropdown to true. Second, if the user selects "Edit", you will have to add this code MyDetailsView.ChangeMode(DetailsViewMode.Edit); otherwise you will force the user to take another step to enter edit mode. hope it helps, it takes a little bit to get used to the new controls but once you do they are great.

                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