c# - Displaying Column Headers As Dates Telerik Rad Grid -
normally have code post. however, i'm not sure start on one. maybe incorrect request little different (from clients). so, needing new feature added page. want able run report shows employees total hours given set of weeks. use datepicker select start date , select , end date. then, click button run report. report have employee name first column , each column after have header date. if selected 8-5-2017 , 8-19-2017 column headers 8-5-2017| 8-12-2017| 8-19-2017. underneath columns total hours each employee worked given week.
i've attached image of needing do. provide additional clarification.
i've had similar situation , managed solve using datatable
contained data. simple way fill datatable
creating stored procedure.
in example i'll every day between 2 given dates, should able change code have work once every 7 days, starting on monday/sunday, depending on requirement is. if need well, leave comment , i'll see can if find time.
create type [dbo].[daytabletype] table( [datum] [date] not null, [daycol] [int] not null ) go create procedure [dbo].[mystoredprocedure] -- add parameters stored procedure here @d1 datetime, @d2 datetime begin -- set nocount on added prevent result sets -- interfering select statements. set nocount on; set datefirst 1; -- insert statements procedure here declare @startdate date = convert(date, @d1); declare @enddate date = convert(date, @d2); declare @days dbo.daytabletype; cte ( select @startdate datum union select dateadd(day,1,datum) datum cte dateadd(day,1,datum) <= @enddate ) insert @days select cte.datum, datepart(day, cte.datum) cte option(maxrecursion 0); declare @dpivot nvarchar(max) select @dpivot = '' select @dpivot = @dpivot + '[' + convert(varchar(8),d.datum,3) + '],' @days d select @dpivot = substring(@dpivot,1,len(@dpivot)-1) declare @sqlstr nvarchar(max); set @sqlstr = 'select p.employeeid ,p.lastname ,p.firstname ,'+ @dpivot + ' (select convert(varchar(8),d.datum,3) daycol ,e.employeeid ,e.lastname ,e.firstname ,isnull((select sum(w.workedhours) dbo.[employeeworkdatetable] w w.employeeid = e.employeeid , convert(date, w.workdate) = convert(date, d.datum)),0) dayinfo @days d left outer join dbo.[employeetable] e on e.isactive = 1 ) t pivot ( max(t.daginfo) t.dagcol in (' + @dpivot + ') ) p order p.lastname' execute sp_executesql @sqlstr, n'@days daytabletype readonly, @startdate date, @enddate date', @days, @startdate, @enddate end
this should return datatable
looks lot you've posted in screenshot. have display correctly gridview
have need first in viewmodel followed:
private datatable _mydatatable; public datatable mydatatable { { return _mydatatable; } set { setproperty(ref _mydatatable, value); } } public void fillmydatatable() { using (var conn = new sqlconnection("myconnectionstring")) using (var cmd = new sqlcommand("mystoredprocedure", conn) { commandtype = system.data.commandtype.storedprocedure }) { cmd.parameters.addwithvalue("@d1", startdate); cmd.parameters.addwithvalue("@d2", enddate); var da = new sqldataadapter(cmd); var ds = new dataset(); da.fill(ds); mydatatable = ds.tables[0]; } }
now should bind gridview
itemsource defaultview
property of datatable
, have autogeneratecolumns="true"
, can edit column names , other stuff more writing custom emplementation of autogeneratingcolumn
<telerik:radgridview x:name="mygridview" autogeneratecolumns="true" itemssource="{binding mydatatable.defaultview}" autogeneratingcolumn="mygridview_onautogeneratingcolumn"> </telerik:radgridview>
i hope helps out problem. feel free leave comment if have more questions.
Comments
Post a Comment