locked
loop through code to make it more generic RRS feed

  • Question

  • User1717218719 posted

    I have code which gets data based on column number from a gridview. to avoid having big long repetative pieces of code I decided to make a generic function. The problem I have now is that i am unsure how to code it so it goes to the next column row without maually in putting it in the code.

    The code I need help with :

    how do I code it so it goes to column  c(1) then c(2) etc :

    objTblNbrs = (From c In argMstTblNbrs Select c(0)).Distinct.ToList()

     

    Tuesday, May 7, 2019 1:37 PM

All replies

  • User475983607 posted

    I do not understand the code.  Are you trying to build dynamic SQL?

    Tuesday, May 7, 2019 2:28 PM
  • User288213138 posted

    Hi E.RU,


    According to your description, I couldn’t understand your requirement clearly.


    You said you want to gets data based on column number from a gridview, but in your code, it get value by the index, In that case, only GridViewRow can do that. So please  describe your question clearly.

     

    And do you want to get data from the GridView or GridView DataSource (such as DataTable)?

     

    Best Regard,
    Sam

    Wednesday, May 8, 2019 10:02 AM
  • User1717218719 posted

    I want to know if I can code it so it loops through the columns in a gridview. thats the code  I have so far,  I change the zero to 1 each time to get new column.

    Thursday, May 9, 2019 8:19 AM
  • User753101303 posted

    And you can't just use a variable rather than 0 ie something such as :

                var t = new DataTable();
                t.Columns.Add("A");
                t.Columns.Add("B");
                t.Rows.Add("a", "b");
                t.Rows.Add("a", "c");
                for(int i=0;i<t.Columns.Count;i++)
                {
                    var q = (from DataRow c in t.Rows select c[i]).Distinct(); // select c(i) using VB ?
                    Console.WriteLine(string.Join(",", q));
                };
    

    shows :

    a
    b,c

    I realized late you are using VB but it should be basically the same idea.

    Thursday, May 9, 2019 10:49 AM