View Single Post
  #1 (permalink)  
Old September 4th, 2008, 08:30 AM
stublair stublair is offline
Registered User
 
Join Date: Jul 2008
Location: london, , .
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Get GridView Cell Value Based on GridView Column

Hi,

I have a GridView which is being generated from dynamic XML. The contents and heading of this table change everytime the web app. is run. The results are being displayed fine and it's all working. What I am after is to be able to pull back the easting and northing cell values of a selected row and store them in a hidden field.

The problem i am having is that the possition of these columns changes therefore whilst the code below works its only going to work for one particular xml doc.

Any suggestions will be greatly received.

S


    protected void FMNGridView_SelectedIndexChanged(object sender, EventArgs e)
    {
        var FMNRowSelected = (string)FMNResultsGridView.SelectedDataKey.Value;


        // Copy the items in the Rows collection into an array.
        GridViewRow[] rowArray = new GridViewRow[FMNResultsGridView.Rows.Count];
        FMNResultsGridView.Rows.CopyTo(rowArray, 0);

        // Iterate though the array and display the value in the specified cell of the row

        int j = -1;
        foreach (GridViewRow row in rowArray)
        {
            j++;
            if (j == FMNResultsGridView.SelectedRow.RowIndex)
            {

                Label1.Text = row.Cells[20].Text;

            }
         }



    }