Several months ago I posted to this forum asking for assistance on a particular issue...Imar graciously helped me out...
Anyway, same project, but I've got a new(ish) problem.
I have a likert score database that pipes instructors, courses, dates, and a series of scores on varied performance metrics to a web front end.
User modifies web controls to receive desired date range, instructor and course(s).
Here's my problem. Everything works great...When user only wants a range defined to include ONE course. When the checkboxlist is asked to send two (or more) courses, only the first course in the list makes it through the SQL statement.
So...I need to cycle through the checkboxlist to form a string of values....A For each list item statement that is tied to either the page load(?) or btnSubmit click event. (???)
I don't know how to configure that. I need help there...hence the
VB part of my title.
Now, once that is configured, I presume I need some type of tweaking to my SQL statement so that it will accept a string into the WHERE clause. Or not. I really don't know.
Here's the code.
Code:
<formid="form1"runat="server">
<asp:ScriptManagerrunat="server"id="ScriptManager1"></asp:ScriptManager>
<br/>
<asp:UpdatePanelid="UpdatePanel1"runat="server">
<ContentTemplate>
<br/>
<spanclass="style2">
<asp:labelid="lblCblCourse"runat="server"style="font-weight: 700"Text="Courses"></asp:label>
</span>
<brclass="style2"/>
<asp:CheckBoxListid="cblCourse"runat="server"DataSourceID="CoursesDataSource"DataTextField="Course"DataValueField="Course"Font-Names="Calibri"Font-Size="Small"RepeatColumns="4">
</asp:CheckBoxList>
<brclass="style2"/>
<brclass="style2"/>
<spanclass="style2">
<asp:labelid="lblInstructor"runat="server"style="font-weight: 700"Text="Instructor"></asp:label>
</span>
<brclass="style2"/>
<spanclass="style1"><spanclass="style3">
<asp:dropdownlistid="ddlInstructor"runat="server"DataSourceID="InstructorsDataSource"DataTextField="Instructor"DataValueField="Instructor">
</asp:dropdownlist>
</span></span>
<brclass="style2"/>
<brclass="style2"/>
<brclass="style2"/>
<tablestyle="width: 100%">
<tr>
<tdstyle="width: 240px"><spanclass="style2">
<asp:labelid="lblStartDate"runat="server"style="font-weight: 700"Text="Start Date"></asp:label>
</span>
<asp:calendarid="calStartDate"runat="server"Font-Names="Calibri"Font-Size="Small"SelectedDate="2008-01-01">
<TitleStyleBackColor="#336699"Font-Bold="True"Font-Names="Calibri"/>
</asp:calendar>
</td>
<td><spanclass="style2">
<asp:labelid="lblEndDate"runat="server"style="font-weight: 700"Text="End Date"></asp:label>
</span>
<asp:calendarid="calEndDate"runat="server"Font-Names="Calibri"Font-Size="Small"SelectedDate="2009-05-26">
<TitleStyleBackColor="#336699"Font-Bold="True"/>
</asp:calendar>
</td>
</tr>
</table>
<brclass="style2"/>
<brclass="style2"/>
<asp:ButtonID="btnSubmit"runat="server"Text="Submit"/>
<brclass="style2"/>
<brclass="style2"/>
<asp:GridViewid="gvData"runat="server"AutoGenerateColumns="False"DataSourceID="ScoresDataSource"Font-Names="Calibri"Font-Size="Small">
<Columns>
<asp:boundfieldDataField="SessionFlow"HeaderText="SessionFlow"ReadOnly="True"SortExpression="SessionFlow">
</asp:boundfield>
<asp:boundfieldDataField="Materials"HeaderText="Materials"ReadOnly="True"SortExpression="Materials">
</asp:boundfield>
<asp:boundfieldDataField="CBT"HeaderText="CBT"ReadOnly="True"SortExpression="CBT">
</asp:boundfield>
<asp:boundfieldDataField="Activities"HeaderText="Activities"ReadOnly="True"SortExpression="Activities">
</asp:boundfield>
<asp:boundfieldDataField="ClarityOfInfo"HeaderText="ClarityOfInfo"ReadOnly="True"SortExpression="ClarityOfInfo">
</asp:boundfield>
<asp:boundfieldDataField="ClassLength"HeaderText="ClassLength"ReadOnly="True"SortExpression="ClassLength">
</asp:boundfield>
<asp:boundfieldDataField="AnswerQs"HeaderText="AnswerQs"ReadOnly="True"SortExpression="AnswerQs">
</asp:boundfield>
<asp:boundfieldDataField="Patience"HeaderText="Patience"ReadOnly="True"SortExpression="Patience">
</asp:boundfield>
<asp:boundfieldDataField="Presentation"HeaderText="Presentation"ReadOnly="True"SortExpression="Presentation">
</asp:boundfield>
<asp:boundfieldDataField="Knowledge"HeaderText="Knowledge"ReadOnly="True"SortExpression="Knowledge">
</asp:boundfield>
<asp:boundfieldDataField="Timeliness"HeaderText="Timeliness"ReadOnly="True"SortExpression="Timeliness">
</asp:boundfield>
<asp:boundfieldDataField="Preparedness"HeaderText="Preparedness"ReadOnly="True"SortExpression="Preparedness">
</asp:boundfield>
<asp:boundfieldDataField="Motivation"HeaderText="Motivation"ReadOnly="True"SortExpression="Motivation">
</asp:boundfield>
<asp:boundfieldDataField="Participation"HeaderText="Participation"ReadOnly="True"SortExpression="Participation">
</asp:boundfield>
</Columns>
</asp:GridView>
<brclass="style2"/>
<brclass="style2"/>
<asp:sqldatasourceid="ScoresDataSource"runat="server"ConnectionString="<%$ ConnectionStrings:OpsCourseEvaluationsConnectionString %>"SelectCommand="SELECT AVG(SessionFlow) AS SessionFlow, AVG(Materials) AS Materials, AVG(CBT) AS CBT, AVG(Activities) AS Activities, AVG(ClarityOfInfo) AS ClarityOfInfo, AVG(ClassLength) AS ClassLength, AVG(AnswerQs) AS AnswerQs, AVG(Patience) AS Patience, AVG(Presentation) AS Presentation, AVG(Knowledge) AS Knowledge, AVG(Timeliness) AS Timeliness, AVG(Preparedness) AS Preparedness, AVG(Motivation) AS Motivation, AVG(Participation) AS Participation FROM View_3 WHERE (Course = @Course) AND (Instructor = @Instructor) AND (CourseDate >= @CalStartDate) AND (CourseDate <= @CalEndDate)">
<SelectParameters>
<asp:ControlParameterControlID="cblCourse"Name="Course"PropertyName="SelectedValue"Type="String"/>
<asp:controlparameterControlID="ddlInstructor"Name="Instructor"PropertyName="SelectedValue"/>
<asp:controlparameterControlID="calStartDate"Name="CalStartDate"PropertyName="SelectedDate"/>
<asp:controlparameterControlID="calEndDate"Name="CalEndDate"PropertyName="SelectedDate"/>
</SelectParameters>
</asp:sqldatasource>
<asp:sqldatasourceid="CoursesDataSource"runat="server"ConnectionString="<%$ ConnectionStrings:CoursesConnectionString %>"SelectCommand="SELECT DISTINCT [CourseID], [Course] FROM [View_3] ORDER BY [Course]">
</asp:sqldatasource>
<asp:sqldatasourceid="InstructorsDataSource"runat="server"ConnectionString="<%$ ConnectionStrings:InstructorsConnectionString %>"SelectCommand="SELECT DISTINCT [InstructorID], [Instructor] FROM [View_3]">
</asp:sqldatasource>
<asp:sqldatasourceid="CourseDatesDataSource"runat="server"ConnectionString="<%$ ConnectionStrings:CourseDatesConnectionString %>"SelectCommand="SELECT [CourseDate] FROM [View_3]">
</asp:sqldatasource>
<brclass="style2"/>
</ContentTemplate>
</asp:UpdatePanel>
</form>
Somebody earlier had helped me configure this as a For Each statement...Would I execute this on a button click? or on page load?
Code:
ProtectedSub btnSubmit_Click(ByVal sender AsObject, ByVal e As System.EventArgs) Handles btnSubmit.Click
Dim inExpression AsNew Text.StringBuilder()
ForEach li As ListItem In cblCourse.Items
If li.Selected Then
inExpression.Append(li.Text + ", ")
EndIf
Next li
If inExpression.Length > 0 Then
inExpression.Remove(inExpression.Length - 2, 1)
EndIf
ScoresDataSource.SelectParameters("Course").DefaultValue = inExpression.ToString().TrimEnd(","c, " ")
EndSub