Re: Identifying Rows

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



On 28 Dec, 23:16, Ben <benm5...@xxxxxxxxx> wrote:
In C#, I have a GridView that bounds to a DataView.
When the user click a certain button, I want it to go through the
gridview rows and update some object based on an ID.

The ID should be invisible... so I put a <LABEL> in one of the cells
and trying to access it via FindControl... but it's always returning
null.

I even made each LABEL have it's own ID (being equal to MonitorID1, 2,
3... etc), it's still not getting it.. here's a snippet, maybe someone
has ideas on what's wrong?

protected void btnSetMaintenance_Click(object sender, EventArgs e)
        {
            int iCount = 0;
            foreach (GridViewRow gvr in gridIssues.Rows)
            {
                Label lbl =
(Label)gvr.Cells[1].FindControl("MonitorID" + iCount.ToString());

                if(lbl != null)
                    Response.Write(lbl.Text + "<BR>");
                else
                    Response.Write("not found (" + gvr..Cells[1].Text +
iCount.ToString() + "<BR>");

                iCount++;
            }
        }

Thank you!

Hi Ben

(In deference to Mark) I've noticed that a lot of posters on this
forum fail to differentiate properly between the underlying data from
what is displayed in databound controls. If you wish to update the
data table then use a query to retreive it, modify it and apply the
updates using ADO.NET Databound controls can then be refreshed with
the Databind() method. It may well be that only an individual record
needs updating in some way, where its identity is signalled by user
selection from a grid, but in those cases it's only the primary key
that is needed.

The newly introduced data controls in ASP.NET v 2 did extend the
automatic updating from databound columns etc quite considerably, but
that only works for individual rows when in edit mode. Wider updates
have to be applied separately in the manner suggested above.
.


Quantcast