p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   C# 2008 aka C# 3.0 (http://p2p.wrox.com/forumdisplay.php?f=354)
-   -   Get GridView Cell Value Based on GridView Column (http://p2p.wrox.com/showthread.php?t=70406)

stublair September 4th, 2008 08:30 AM

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;

            }
         }



    }




All times are GMT -4. The time now is 07:34 PM.

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.