none
How can I use subgrid like functionality in reportviewer? RRS feed

  • Question

  • Hi,

    I have to display a report like--

    Qst # Subject Weight Question
    1 Physics 1 Question 1 of Physics.
    Option # Score Next Option # Options
    1 0 2 Option 1 of Question 1
    2 1 2 Option 2 of Question 1
    3 2 Option 3 of Question 1
    Chemistry 1 Question 2 of Chemistry.
    Option # Score Next Option # Options
    1 1 3 Option 1 of Question 2
    2 2 3 Option 2 of Question 2
    3 3 3 Option 3 of Question 2
    3 Physics 1 Question 3 of Physics.
    Option # Score Next Option # Options
    1 1 4 Option 1 of Question 3
    2 4 Option 2 of Question 3
    3 1 4 Option 2 of Question 3

    As of now I am using SubGrid (Grid inside Grid i.e. first Grid to bind the Question and second to bind the Options for that Question) on my .aspx page and manually binding from code behind on "onRowDataBound" and I am successfully achieving this.

    How can I achieve the same functionality with the help of ReportViewer and which control should I use inside .rdlc file? Also how to enable paging there with the following condition (while .aspx page data should display according to paging but on Export all the records should exported in the respective format)?

    Below is a sample DB script for convenience--

    create table ModelTest
    (
    [ModelId] int identity,
    [ModelName] nvarchar(100)
    )
    GO
    create table Questions
    (
    [QuestionID] int identity,
    [ModelId] int,
    [Subject] nvarchar(100),
    [QstNo] int,
    [Question] nvarchar(1000),
    [Weight] int
    )
    GO
    create table Options
    (
    [OptionID] int identity,
    [QuestionID] int,
    [OptionNo] int,
    [OptionText] nvarchar(1000),
    [Score] int,
    [NextQstNo] int
    )
    GO
    insert into ModelTest(ModelName) values('General Awareness')
    GO
    insert into Questions(ModelId,Subject,QstNo,Question,Weight)
    select 1,'Physics',1,'Question 1 of Physics.',1
    union all
    select 1,'Chemistry',1,'Question 2 of Chemistry.',1
    union all
    select 1,'Physics',1,'Question 3 of Physics.',1
    GO
    insert into Options(QuestionID,OptionNo,OptionText,Score,NextQstNo)
    select 1,1,'Option 1 of Question 1',0,2
    union all
    select 1,2,'Option 2 of Question 1',1,2
    union all
    select 1,3,'Option 3 of Question 1',2,2
    union all
    select 2,1,'Option 1 of Question 2',1,3
    union all
    select 2,2,'Option 2 of Question 2',2,3
    union all
    select 2,3,'Option 3 of Question 2',3,3
    union all
    select 3,1,'Option 1 of Question 3',1,4
    union all
    select 3,2,'Option 2 of Question 3',1,4
    union all
    select 3,3,'Option 3 of Question 3',1,4
    GO
    create procedure uspGetModelPaper
    (
    	@ModelId int
    )
    AS
    set nocount on
    select A.ModelId,A.ModelName,B.QuestionID,B.Question,B.Subject,B.Weight,B.QstNo
    ,C.OptionID,C.OptionText,C.OptionNo,C.Score,C.NextQstNo
    from ModelTest A
    inner join Questions B on A.ModelId=B.ModelId and B.ModelId=@ModelId
    inner join Options C on B.QuestionID=C.QuestionID
    where A.ModelId=@ModelId
    set nocount off
    GO
    exec uspGetModelPaper 1
    GO

    Thanks in advance,

    Satyendra Maddeshiya






    Friday, August 10, 2012 12:44 PM