How to compare a row and column in a datagrid in asp.net using c#?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sri devi
    New Member
    • Sep 2010
    • 7

    How to compare a row and column in a datagrid in asp.net using c#?

    Hi Frnz,

    I have 2 datsets named ds and ds1 and merged that datasets into a single table named dt. Now, i want to compare the first dataset row value with second dataset column values For Ex: 1 dataset row contains the value as "SriDevi" means, i want to compare and find how many times the value "SriDevi" appears in second dataset columns and count the appearance. And give the answer as the "count". The answer is displayed in First Dataset. How?

    Anyone please help me!!!!

    Code:
    Code:
                int rowcount;
                DataRow dr = dt.Rows[0];
                for (int j = 1; j < dt.Rows.Count; j++)
                {
                    if (ds.Tables[0].Rows[0][1].ToString() == ds1.Tables[0].Rows[j][4].ToString())
                    {
                        rowcount = ds1.Tables[0].Rows.Count;
                        dr["Attendees"] = rowcount;
                    }
                }
    Thanks,
    Sri Devi S
    Last edited by Frinavale; Oct 8 '10, 08:37 PM. Reason: Please post code in [code] ... [/code] tags. Added code tags.
  • Frinavale
    Recognized Expert Expert
    • Oct 2006
    • 9749

    #2
    You should be able to use the DataTable.Selec t method to achieve what you are looking to do.

    -Frinny

    Comment

    Working...