Skip to content

How to assign value to datagrid column

sita k

Asked Sep 20, 2013, 11:04 PM EDT1 answer
Share
LinkedInX

Hello Everyone,

        I got an employee_Works table with columns eid,ename,sdate,edate,wages/day.Now I need to calculate his salary based on sdate and edate. Below are the steps what I followed :
         In addition to the other columns i added a boundfiled to gridview manually for salary because it's not a column in this table.I am not sure whether i can do it manually or not.Now I calculated the difference between the dates.

            DateTime d1 = DateTime.Parse(sdate);
           DateTime d2 = DateTime.Parse(edate);
           TimeSpan ds = d2 -d1;DateTime d1 = DateTime.Parse(sdate);
           DateTime d2 = DateTime.Parse(edate);
           TimeSpan ds = d2 -d1;
   
            float sal = ds * wages;

       Now I need to assign this value to the grid view for Salary cell.Let me know how to proceed?

1 Answer

Know the answer? Post it. Somebody with the same question will find it here.

  • 0
    Hello,

          I wrote the below query:

               DateTime d1 = DateTime.Parse(sdate);
               DateTime d2 = DateTime.Parse(edate);
               TimeSpan ds = d2 -d1;DateTime d1 = DateTime.Parse(sdate);
               DateTime d2 = DateTime.Parse(edate);
               TimeSpan ds = d2 -d1;

        select emp_id,emp_name,sdate,edate,wages,wages * ds as SAL from employee_Works;

       What is wrong with this query getting an error invalid identifier at ds.

       and trying to assign the value ds to the grid view.

       grdView.Rows[3].Cells[3].Text = SAL;

       Getting an error index out of range. Must be non-negative and less than size of collection.

    Regards.

    0