DataGrid

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Sakalicek
    New Member
    • Mar 2007
    • 51

    #1

    DataGrid

    Hi all, could you please help me with my problem?

    I have created DataGrid with Edit button and I want to have there also Delete button on each row.

    But there should be some functionality like if user click on Delete, Delete link should change to two links "Yes" and "No". And than if user click Yes, row will be deleted.

    I did it with setting Visible to true or false.
    But I am not able to identify LinkButtons for Yes and No in DataGrid.

    The main uestionn is, "how identify other objects in DataGrid row if I click on some object in that row.".

    I need e.c. disable all the row before deleting.


    Understand?

    Thx 4 any help.

    Zdenek.
  • jhardman
    Recognized Expert Specialist
    • Jan 2007
    • 3405

    #2
    moved to .NET forum

    Comment

    • nateraaaa
      Recognized Expert Contributor
      • May 2007
      • 664

      #3
      Originally posted by Sakalicek
      Hi all, could you please help me with my problem?

      I have created DataGrid with Edit button and I want to have there also Delete button on each row.

      But there should be some functionality like if user click on Delete, Delete link should change to two links "Yes" and "No". And than if user click Yes, row will be deleted.

      I did it with setting Visible to true or false.
      But I am not able to identify LinkButtons for Yes and No in DataGrid.

      The main uestionn is, "how identify other objects in DataGrid row if I click on some object in that row.".

      I need e.c. disable all the row before deleting.


      Understand?

      Thx 4 any help.

      Zdenek.
      You will need to use a CommandName for each of your controls in that cell. Let's assume that you have 5 columns in your datagrid. The last column has 3 controls a Delete Button, a Yes hyperlink, and a No hyperlink. Assign a CommandName to each control.
      Delete Button Command Name = "Delete"
      Yes Hyperlink CommandName = "Yes"
      No Hyperlink CommandName = "No"

      Now for the datagrid add an ItemCommand Event to the datagrid. Go to properties and click the lightning bolt to see the events of the datagrid. Double click on ItemCommand.
      Now in your code behind file add the following code to the new datagrid event:

      Code:
      //Make sure Yes and No linkbuttons are set to Visible = false;
      Button buttonDelete = (Button) e.Item.Cells[4].FindControl("nameofyourDeletebutton");
      LinkButton linkbuttonYes = (LinkButton) e.Item.Cells[4].FindControl("nameofyourYeshyperlink");
      LinkButton linkbuttonNo = (LinkButton) e.Item.Cells[4].FindControl("nameofyourNohyperlink");
      switch(e.CommandName)
      {
      case: "Delete"
      linkbuttonYes.Visible = true;
      linkbuttonNo.Visible = true;
      buttonDelete.Visible = false;
      break;
      case: "Yes"
      //call your delete proc here
      //Make sure to rebind the grid after this so that row will be removed from the UI
      linkbuttonYes.Visible = false;
      linkbuttonNo.Visible = false;
      buttonDelete.Visible = true;
      break;
      case: "No"
      //Don't delete just show grid again in normal state
      linkbuttonYes.Visible = false;
      linkbuttonNo.Visible = false;
      buttonDelete.Visible = true;
      default:
      break;
      }
      This should get you on the right track.

      Nathan
      Last edited by nateraaaa; Aug 31 '07, 05:21 PM. Reason: Added code tags around code example

      Comment

      • Sakalicek
        New Member
        • Mar 2007
        • 51

        #4
        Brilliant :D

        Thanks a lot man.

        Zdenek.


        Originally posted by nateraaaa
        You will need to use a CommandName for each of your controls in that cell. Let's assume that you have 5 columns in your datagrid. The last column has 3 controls a Delete Button, a Yes hyperlink, and a No hyperlink. Assign a CommandName to each control.
        Delete Button Command Name = "Delete"
        Yes Hyperlink CommandName = "Yes"
        No Hyperlink CommandName = "No"

        Now for the datagrid add an ItemCommand Event to the datagrid. Go to properties and click the lightning bolt to see the events of the datagrid. Double click on ItemCommand.
        Now in your code behind file add the following code to the new datagrid event:

        Code:
        //Make sure Yes and No linkbuttons are set to Visible = false;
        Button buttonDelete = (Button) e.Item.Cells[4].FindControl("nameofyourDeletebutton");
        LinkButton linkbuttonYes = (LinkButton) e.Item.Cells[4].FindControl("nameofyourYeshyperlink");
        LinkButton linkbuttonNo = (LinkButton) e.Item.Cells[4].FindControl("nameofyourNohyperlink");
        switch(e.CommandName)
        {
        case: "Delete"
        linkbuttonYes.Visible = true;
        linkbuttonNo.Visible = true;
        buttonDelete.Visible = false;
        break;
        case: "Yes"
        //call your delete proc here
        //Make sure to rebind the grid after this so that row will be removed from the UI
        linkbuttonYes.Visible = false;
        linkbuttonNo.Visible = false;
        buttonDelete.Visible = true;
        break;
        case: "No"
        //Don't delete just show grid again in normal state
        linkbuttonYes.Visible = false;
        linkbuttonNo.Visible = false;
        buttonDelete.Visible = true;
        default:
        break;
        }
        This should get you on the right track.

        Nathan

        Comment

        • rohitbce
          New Member
          • Aug 2007
          • 30

          #5
          Hi
          you have one more option to do like that just give one link button in datagrid Delete and that click event call the javaScript its only a one line code call confirm method so it will be ask yes or no............. ...............
          do it like that may be it will work
          Thanks & regard
          Rohit Jain

          Comment

          • Sakalicek
            New Member
            • Mar 2007
            • 51

            #6
            Ok I know this oportunity but want to do it this way.
            nevertheless, thank u for advice.

            Originally posted by rohitbce
            Hi
            you have one more option to do like that just give one link button in datagrid Delete and that click event call the javaScript its only a one line code call confirm method so it will be ask yes or no............. ...............
            do it like that may be it will work
            Thanks & regard
            Rohit Jain

            Comment

            • phanimadhav
              New Member
              • Jun 2007
              • 78

              #7
              how to place the conform to menu items

              Comment

              • Sakalicek
                New Member
                • Mar 2007
                • 51

                #8
                Did you mean "how to place confirm" or what?
                There could be placed validators.
                E.g. CustomValidator s or RequiredFieldVa lidators. Or you could add some code just into functions routed with the specific item in Grid.



                Originally posted by phanimadhav
                how to place the conform to menu items

                Comment

                Working...