The_Fruitman:

The way I prefer is using the "as" keyword. It obviates the need to
handle the InvalidCastException thrown in explicit casts:

TextBox txt1 = e.Item.FindControl("NameOfTextBox") as TextBox;
if (txt1 != null)
{
  // Successful cast.
}

I perform almost all casts using the as keyword.

On May 19, 6:58 pm, The_Fruitman <[email protected]> wrote:
> The way I've done it in the past is
> TextBox txt1 = (TextBox)(e.Item.FindControl("NameOfTextBox"));
>
> Where e is type DataGridCommandEventArgs
>

Reply via email to