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.
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.
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);
}
}
}
I assume you are approaching through following ways...
- You have a footer template and may have a button which saves the values from your footer.
- You have an Edit/Update button in grid for each row
You can find like below...
TextBox testing = (TextBox)grd.FooterRow.FindControl("Your Control ID");
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>