Use Eval in C# foreach loop?

DB_Fury
DB_Fury used Ask the Experts™
on
I just started working with C# and I  am used to working with Classic ASP.  I am trying to create a dynamic SQL update statement (the set clause) from arrays of data that I have complied.  I am looping throught the columns and i want to attach a "= value," to each of those columns.  My problem is I dont know how to create new names for each of the textboxes i.e. (TextBox)row.Cells[1].Controls[0]; where the 1 would be a counter variable (i)?  In classic asp i would use the eval function but I have no idea what to do in c#, plase help. I have included the code for when i click update link on the datagrid.



protected void dgSelectedRow_RowUpdating(object sender, GridViewUpdateEventArgs e)
    {
        string LookupTable = ddlLookupTables.SelectedItem.Value;
        GridViewRow row = dgSelectedRow.Rows[e.RowIndex];
        TextBox txt1 = (TextBox)row.Cells[1].Controls[0];
        string t = txt1.Text;

        string ColNames = Tables.GetTableColumns(LookupTable);
        string[] strArray = ColNames.Split(',');

        int i = 1;
        string Update;
        foreach (string str in strArray)
        {
            TextBox eval["txt"+ i] = (TextBox)row.Cells[i].Controls[0];
            Update += str + "=" + eval["txt"+ i];
            i += 1;
        }

Open in new window

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Commented:
as far as I know there is no eval - c# is compiled not interpreted.
you can use something like

 TextBox t = Controls.Find("txt" + i.ToString()):
 Update += str + "=" + t.Text;
Top Expert 2013
Commented:
Not sure why you are trying to find the Textbox control
You can get the values using e.NewValues[cellindex]
e.g.
string firstcellText =(string) e.NewValues[0];
string secondcellText =(string) e.NewValues[1];

So may be your update could be:
foreach (string str in strArray)
        {
           Update += str + "=" + e.NewValues[i].ToString();
            i += 1;
        }

Author

Commented:
Thank you both very much for your comments, I left for lunch and came back to find answer.  Im glad I joined the exchange today!
HTML5 and CSS3 Fundamentals

Build a website from the ground up by first learning the fundamentals of HTML5 and CSS3, the two popular programming languages used to present content online. HTML deals with fonts, colors, graphics, and hyperlinks, while CSS describes how HTML elements are to be displayed.

Commented:
you are welcome

Commented:
maybe you can close this one

Author

Commented:
fgd

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial