Search code examples
c#findcontrol

findcontrol textbox text without declaring variable c#


Is there a way to turn these two lines of code into a single line of

TextBox tempTextBox= grdvwEncroachmentsID.Rows[e.RowIndex].FindControl("txtbxBillTo") as TextBox;
string billToTemp = tempTextBox.Text;

Solution

  • Just delete the Line Break!

    Just kidding. I assume you mean single statement.

    Here you go:

    string billToTemp = (grdvwEncroachmentsID.Rows[e.RowIndex].FindControl("txtbxBillTo") as TextBox).Text;
    

    Not sure why you would do this, though. It's ugly.