Advertisement

03.10.2008 at 09:35AM PDT, ID: 23228957
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

ASP.Net - Repeater control and if statement

Tags: Microsoft, ASP.Net, 2.0, Repeater control and if statement
Hi, I am trying to set up an ASP.net form that displayes a group of 4 radio buttons, a questions then a group of 3 radio buttons.

Some questions have sub questions, so the sub question will have the radiobuttons and the parent question will not.  How do create an if statement to check and see if the parent should have these shown?  I have a column in my table that says whether it should or not for ease.  Current code attached.
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
//Repeater code
<table width="100%" cellpadding="0" cellspacing="0" border="0">
    <asp:Repeater runat="server" ID="RepWorkArea" OnItemDataBound="ShowQuestions">
        <ItemTemplate>
            <tr>
                <td colspan="3">
                    <h4><%# ((DataRowView)Container.DataItem)["WorkArea"]%></h4>
                </td>
            </tr>
            <asp:Repeater ID="RepQuestions" OnItemDataBound="ShowSubQuestions" runat="server">
                <itemtemplate> 
                <tr>
                    <td width="90px"><asp:RadioButtonList ID="radQuestionList" runat="server" DataSourceID="SqlDataSource1" DataValueField="SkillImportanceID" OnSelectedIndexChanged="btnViewSkill_Click" RepeatDirection="Horizontal" DataTextField="empty" RepeatLayout="flow"/></td>
                    <td width="*"><b><%# (Container.ItemIndex + 1) %>.</b> <%# ((DataRowView)Container.DataItem)["Question"]%></td>
                    <td width="70px" align="right"><asp:RadioButtonList ID="radSubQuestionList" runat="server" DataSourceID="SqlDataSource2" DataValueField="AnswerID" RepeatDirection="Horizontal" DataTextField="empty" RepeatLayout="flow"/></td>
                </tr>
                <tr>
                    <td colspan="3" align="left">
                        <table width="100%"  cellpadding="0" cellspacing="0" border="0">
                            <asp:repeater id="RepSubQuestions" runat="server"> 
                                <itemtemplate>
                                <tr>
                                    <td width="90px">
                                        <asp:RadioButtonList ID="radQuestionList" runat="server" DataSourceID="SqlDataSource1" DataValueField="SkillImportanceID" OnSelectedIndexChanged="btnViewSkill_Click" RepeatDirection="Horizontal" DataTextField="empty" RepeatLayout="flow"/>
                                    </td>
                                    <td width="*">
                                        <div id="SubQuestions">
                                            <li class="bold"><%# DataBinder.Eval(Container.DataItem, "[\"Question\"]")%></li>
                                        </div>
                                    </td>
                                    <td width="70px" align="right">
                                        <asp:RadioButtonList ID="radSubQuestionList" runat="server" DataSourceID="SqlDataSource2" DataValueField="AnswerID" RepeatDirection="Horizontal" DataTextField="empty" RepeatLayout="flow"/>
                                    </td>
                                </tr>
                                </itemtemplate> 
                            </asp:repeater>   
                        </table>
                    </td>
                </tr>
                </itemtemplate> 
            </asp:Repeater>
        </ItemTemplate>
    </asp:Repeater>
 
//Code Behind
private SqlConnection connString = new SqlConnection(WebConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString.ToString());
        
    protected void Page_Load(object sender, EventArgs e)
    {
        string strSql;
        DataSet ds = new DataSet();
        strSql = "select distinct A.* from WorkAreas as A right Join EvaluationQuestions AS B on a.WorkAreaId = B.WorkAreaID AND B.EvaluationID = 1 Order By A.SortOrder";
        SqlDataAdapter daWorkAreas = new SqlDataAdapter(strSql, connString);
        daWorkAreas.Fill(ds, "WorkAreas");
        strSql = "select * from EvaluationQuestions WHERE ParentId = -1 AND Active = 1 AND EvaluationID = 1 Order By EvaluationQuestionID";
        SqlDataAdapter daEvaluationQuestions = new SqlDataAdapter(strSql, connString);
        daEvaluationQuestions.Fill(ds, "EvaluationQuestions");
        strSql = "select * from EvaluationQuestions WHERE Active = 1 AND EvaluationID = 1 Order By EvaluationQuestionID";
        SqlDataAdapter daSubQuestions = new SqlDataAdapter(strSql, connString);
        daSubQuestions.Fill(ds, "SubQuestions");
        DataRelation rel = new DataRelation("QuestionsRel",ds.Tables["WorkAreas"].Columns["WorkAreaID"], ds.Tables["EvaluationQuestions"].Columns["WorkAreaID"],false);
        ds.Relations.Add(rel);
        DataRelation rel2 = new DataRelation("QuestionsRel2", ds.Tables["EvaluationQuestions"].Columns["EvaluationQuestionID"], ds.Tables["SubQuestions"].Columns["ParentID"], false);
        ds.Relations.Add(rel2);
        RepWorkArea.DataSource = ds.Tables["WorkAreas"].DefaultView;
        RepWorkArea.DataBind();
        connString.Close();
 
    }
 
    public void ShowQuestions(Object sender, RepeaterItemEventArgs e)
    {
        if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
        {
            ((Repeater)e.Item.FindControl("RepQuestions")).DataSource =
            ((DataRowView)e.Item.DataItem).CreateChildView("QuestionsRel");
            ((Repeater)e.Item.FindControl("RepQuestions")).DataBind();
        }
    }
 
    public void ShowSubQuestions(Object sender, RepeaterItemEventArgs e)
    {
        if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
        {
            ((Repeater)e.Item.FindControl("RepSubQuestions")).DataSource =
            ((DataRowView)e.Item.DataItem).CreateChildView("QuestionsRel2");
            ((Repeater)e.Item.FindControl("RepSubQuestions")).DataBind();
        }
    }
Start your free trial to view this solution
Question Stats
Zone: Programming
Question Asked By: iftech
Solution Provided By: iftech
Participating Experts: 1
Solution Grade: A
Views: 169
Translate:
Loading Advertisement...
03.10.2008 at 12:25PM PDT, ID: 21089456

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
04.01.2008 at 11:19AM PDT, ID: 21256615

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
Loading Advertisement...
20080236-EE-VQP-29 / EE_QW_2_20070628