0

I'm trying on gridview updated to check if a cell from a certain column is != NULL ( to check if the user wrote something into the cell)

My problem is I don't know how to get the "x column" value from cell.

Pankaj
  • 9,749
  • 32
  • 139
  • 283
Inzi Irina
  • 267
  • 2
  • 5
  • 14

2 Answers2

1

inzi irina Please look at this code. don't forget to vote me if this helps you

private void button2_Click(object sender, EventArgs e)
    {
        foreach (DataGridViewRow dr in dataGridView1.Rows)
        {
            string lngth = Convert.ToString(dr.Cells[1].Value);
            if (lngth.Length > 0)
            {
                listBox1.Items.Add(dr.Cells[0].Value);
            }
        }
    }
0

I assume you are approaching through following ways...

  1. You have a footer template and may have a button which saves the values from your footer.
  2. You have an Edit/Update button in grid for each row

For Approach 1(i.e. Footer Template)

You can find like below...

TextBox testing = (TextBox)grd.FooterRow.FindControl("Your Control ID");

For Approach 2 (i.e. using Edit/Update Button)

You can do like below..

Sample Code Behind

protected void grd_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
    TextBox testing = (TextBox)grd.Rows[e.RowIndex].FindControl("Your Control ID");
}

Sample HTML

<asp:GridView ID="grd" runat="server" onrowupdating="grd_RowUpdating">
</asp:GridView>
Pankaj
  • 9,749
  • 32
  • 139
  • 283