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()
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
.NET forums are moving to a new home on Microsoft Q&A, we encourage you to go to Microsoft Q&A for .NET for posting new questions and get involved today.
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.
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.
Member
51 Points
180 Posts
loop through code to make it more generic
May 07, 2019 01:37 PM|E.RU|LINK
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 :
All-Star
53001 Points
23596 Posts
Re: loop through code to make it more generic
May 07, 2019 02:28 PM|mgebhard|LINK
I do not understand the code. Are you trying to build dynamic SQL?
Contributor
3370 Points
1409 Posts
Re: loop through code to make it more generic
May 08, 2019 10:02 AM|samwu|LINK
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
Member
51 Points
180 Posts
Re: loop through code to make it more generic
May 09, 2019 08:19 AM|E.RU|LINK
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.
All-Star
48500 Points
18071 Posts
Re: loop through code to make it more generic
May 09, 2019 10:49 AM|PatriceSc|LINK
And you can't just use a variable rather than 0 ie something such as :
shows :
I realized late you are using VB but it should be basically the same idea.