Rauf
Rauf

Reputation: 12842

gridview asp.net

my grid view contains a column having a text box. when i post back the page, i have to select all the rows where the value of each row's text box is > 0. how can i do it ?

Upvotes: 0

Views: 75

Answers (2)

i100
i100

Reputation: 4666

Try something like this:

foreach (GridViewRow row in GridView1.Rows)   {
    // Selects the text from the TextBox
    // which is inside the GridView control

    string textBoxText = ((TextBox)row.FindControl("TextBox1")).Text;
    // do waht ever
}

Upvotes: 1

Linkgoron
Linkgoron

Reputation: 4870

You could use LINQ.

var selectedRows = GridView1.Rows.OfType<GridViewRow>().Where(r=>((TextBox)row.FindControl("TextBox")).Text=="val")

and then foreach over the selected rows

Upvotes: 1

Related Questions