Community discussion forum

how to display the datas in single line?

Tags: .net, asp.net Chile
  • 3 months ago

    I am using .net 2005.i am doing my project in asp.net.
    my project title is master log attendance.
    i want to display datas in single row for same name and id.
    i have 2 table named as attendance and employeedetails.

    The following code has worked very well.But datas are displayed in multiple row for same name and id.

    protected void imgsubmitClick(object sender, ImageClickEventArgs e)
    {
    fromdate = txtfrdate.Text;
    to
    date = txttodate.Text;
    empname = ddlempname.SelectedValue;
    check();
    }
    void check()
    {

    System.TimeSpan dt
    diff = Convert.ToDateTime(todate).Subtract(Convert.ToDateTime(fromdate));
    days = dtdiff.Days;


    dt.Columns.Add(new DataColumn("ID", typeof(string)));
    dt.Columns.Add(new DataColumn("Name", typeof(string)));


    for (int i = 0; i <= days; i++)

    {
    sql
    date = Convert.ToDateTime(fromdate).AddDays(i).ToString("MM/dd/yyyy");
    sql
    date1 = Convert.ToDateTime(fromdate).AddDays(i).ToString("MM/dd/yyyy");


    dt.Columns.Add(new DataColumn(sql
    date1, typeof(string)));
    drow = dt.NewRow();

    com = new SqlCommand("select distinct rpt.empid as EmployeeID,card.username as EmployeeName,min(case when rpt.datetime1='" + sqldate + "' then rpt.datetime1 end) as '" + sqldate + "' from tblcard as card,tblreport as rpt where card.fkdata=rpt.empid and rpt.datetime1='" + sqldate + "' and empid='366' group by rpt.empid,card.username", con);
    dr = com.ExecuteReader();
    while (dr.Read())
    {
    drow[0] = dr.GetString(0);
    drow[1] = dr.GetString(1);

    drow[i+2] ="x";
    dt.Rows.Add(drow);
    }
    dr.Close();


    }



    GV
    musterrole.DataSource = new DataView(dt);
    GV_musterrole.DataBind();

    }

    in above code,i applied query with groupby and distinct in for loop statement.
    using above code,the following output is coming in grid view,

    ID   Name  10/11/2007  10/12/2007 10/13/2007  10/14/2007 10/15/2007
    366  dinesh                       x
    366  dinesh                                         x
    366  dinesh                                                          x
    here 3 lines are displayed using for loop statement for same name and id.
    But I want to display in single line using for loop statement for same name and id as following output.How to do this?
    ID   Name  10/11/2007 10/12/2007 10/13/2007 10/14/2007 10/15/2007
    366 dinesh                        x               x               x

  • Advertisement

    Simply the fastest line-level profiler for .NET ever

    “The low overhead means it has minimal impact on the execution of my program”
    Mark Everest, Development Team Leader, Renault F1 Team Ltd.

    Try out the new ANTS Profiler 4 for yourself. Download your 14-day trial now

  • 2 months ago

     Have you tried this:

    instead of x use 1 for present 0 for absent and do a sum of your rows.

    You will then have only 1 row, and 1 each time the employee is present, 0 when they are absent

     

    Regards

Post a reply

Enter your message below

Sign in or Join us (it's free).