How to get the particularRow values in onclick situation in gridview

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • phanimadhav
    New Member
    • Jun 2007
    • 78

    How to get the particularRow values in onclick situation in gridview

    Hi friends i have one small doubt..Actually myclient requirement is whenever i click the gridview row that particular row will select and store that particular row values in one string variable.Any one know the answer please send the reply.
  • Curtis Rutland
    Recognized Expert Specialist
    • Apr 2008
    • 3264

    #2
    Just use the SelectedIndex property to get to the right row, and then traverse the cells of that row, appending each onto a string.

    Comment

    • phanimadhav
      New Member
      • Jun 2007
      • 78

      #3
      Thanks for ur reply.Actually i need how can select the row in the grid.if i select the particular row which event i can raise?please helpme.

      Comment

      • Curtis Rutland
        Recognized Expert Specialist
        • Apr 2008
        • 3264

        #4
        Make sure that you enable selection for your gridview. The event is called SelectedIndexCh anged.

        Comment

        • deathprincess
          New Member
          • Jul 2008
          • 12

          #5
          Originally posted by insertAlias
          Make sure that you enable selection for your gridview. The event is called SelectedIndexCh anged.
          I have a problem like that before and created this code to identify the selected row in dataridview:

          String str = "";
          String intRow = "";
          Point row = [DataGridView].CurrentCellAdd ress;
          intRow = Convert.ToStrin g(row);

          if (intRow.Length == 9)
          {
          str = intRow.Substrin g(7, 1);
          }
          else
          {
          str = intRow.Substrin g(7, 2);
          }
          int n = int.Parse(str);

          Use "n" as the row index.
          Although this works.
          It is better to use the SelectedIndex property.

          Comment

          • Curtis Rutland
            Recognized Expert Specialist
            • Apr 2008
            • 3264

            #6
            Originally posted by deathprincess
            I have a problem like that before and created this code to identify the selected row in dataridview:

            String str = "";
            String intRow = "";
            Point row = [DataGridView].CurrentCellAdd ress;
            intRow = Convert.ToStrin g(row);

            if (intRow.Length == 9)
            {
            str = intRow.Substrin g(7, 1);
            }
            else
            {
            str = intRow.Substrin g(7, 2);
            }
            int n = int.Parse(str);

            Use "n" as the row index.
            Although this works.
            It is better to use the SelectedIndex property.
            Yeah, I would stick with the SelectedIndex, and the OnSelectedIndex Changed event.

            Comment

            • phanimadhav
              New Member
              • Jun 2007
              • 78

              #7
              Thanks for your reply.Sorry for my latereply.Actua lly i need how can select the GridRow.Means if i click on row i need the total details of that row.But whenever i select the row this time i will get the cell details.But need Row and Cell details also.Waiting for ur reply.

              Comment

              • vaibhavkadian
                New Member
                • Jul 2008
                • 1

                #8
                add OnRowCommand="g rd_RowCommand" to gridview


                add a column
                <asp:ButtonFiel d ButtonType="But ton" CommandName="cm d" Text="CMD" />


                protected void grdApplicationS ettings_RowComm and(object sender, GridViewCommand EventArgs e)
                {
                GridView customersGridVi ew = (GridView)e.Com mandSource;
                int index = Convert.ToInt32 (e.CommandArgum ent);
                GridViewRow row = customersGridVi ew.Rows[index];
                if (e.CommandName. Equals("CMD", StringCompariso n.InvariantCult ureIgnoreCase))
                { //do something
                }
                }

                Comment

                • deathprincess
                  New Member
                  • Jul 2008
                  • 12

                  #9
                  Originally posted by phanimadhav
                  Thanks for your reply.Sorry for my latereply.Actua lly i need how can select the GridRow.Means if i click on row i need the total details of that row.But whenever i select the row this time i will get the cell details.But need Row and Cell details also.Waiting for ur reply.
                  You have to set datagridview property, selection mode to full row select.
                  then use the datagridview.Se lectedRows[0].Cells[cell index].value
                  This gets the value associated with the cell of the selected row.

                  Comment

                  Working...