Proper method to create survey page in asp.net / visual web developer 2005

Scamquist
Scamquist used Ask the Experts™
on
I am using Visual Web Developer 2005 and SQL Server 2005 Express to track the status of a project.  I have a table called WeekObjectiveStatus.  This table has 5 fields:

ID
Objective
WeekEnd
ObjectiveStatus
ObjectiveStatusComments

I am trying to get a page to have the project manager easily update the status of the project on a weekly basis.

Idealy,  all Objectives (from a table called Objectives) would be displayed on a grid and the manager would update the  WeekEnd, ObjectiveStatus and ObjectiveStatusComments.

Here is were my problem is.
      I only want one row for each objective
      The ObjectiveStatus should be a RadioButtonList (Red, Yellow and Green)
      If the ObjectiveStatus is not Green, they must enter an ObjectiveStatusComment.

I am trying to figure out the best method.  GridVIew, Repeater, etc.  I don't think I can hardcode a table because there may be new Objectives added in the future.  Any help getting started will be appreciated.
SurveyGrid.jpg
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Hi,

Why not do something simple like the attached sample.

/Carl.
ProjectSurveyGrid.aspx:
 
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="ProjectSurveyGrid.aspx.vb" Inherits="ProjectSurveyGrid" %>
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:GridView ID="GridView1" runat="server" DataSourceID="gvDataSource" 
            AutoGenerateColumns="False" DataKeyNames="ID">
            <Columns>
                <asp:CommandField ShowEditButton="True" />
                <asp:BoundField DataField="ID" HeaderText="ID" InsertVisible="False" 
                    ReadOnly="True" SortExpression="ID" Visible="False" />
                <asp:BoundField DataField="Objective" HeaderText="Objective" 
                    SortExpression="Objective" />
                <asp:BoundField DataField="WeekEnd" HeaderText="WeekEnd" 
                    SortExpression="WeekEnd" />
                <asp:TemplateField HeaderText="ObjectiveStatus" 
                    SortExpression="ObjectiveStatus">
                    <EditItemTemplate>
                        <asp:HiddenField ID="hfStatus" runat="server" Value='<%# Bind("ObjectiveStatus") %>' />
                        <asp:RadioButtonList ID="rblStatus" runat="server" RepeatDirection="Horizontal" Enabled="true" OnSelectedIndexChanged="rblStatusChanged" AutoPostBack="true">
                            <asp:ListItem Text="Green" Value="Green">
                            </asp:ListItem>
                            <asp:ListItem Text="Yellow" Value="Yellow">
                            </asp:ListItem>
                            <asp:ListItem Text="Red" Value="Red">
                            </asp:ListItem>                            
                        </asp:RadioButtonList>
                    </EditItemTemplate>
                    <ItemTemplate>
                        <asp:HiddenField ID="hfStatus" runat="server" Value='<%# Bind("ObjectiveStatus") %>' />
                        <asp:RadioButtonList ID="rblStatus" runat="server" RepeatDirection="Horizontal" Enabled="false">
                            <asp:ListItem Text="Green" Value="Green">
                            </asp:ListItem>
                            <asp:ListItem Text="Yellow" Value="Yellow">
                            </asp:ListItem>
                            <asp:ListItem Text="Red" Value="Red">
                            </asp:ListItem>                            
                        </asp:RadioButtonList>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="ObjectiveStatusComment" 
                    SortExpression="ObjectiveStatusComment">
                    <EditItemTemplate>
                        <asp:TextBox ID="txtObjectiveStatusComment" runat="server" 
                            Text='<%# Bind("ObjectiveStatusComment") %>'></asp:TextBox>
                    </EditItemTemplate>
                    <ItemTemplate>
                        <asp:Label ID="lblObjectiveStatusComment" runat="server" 
                            Text='<%# Bind("ObjectiveStatusComment") %>'></asp:Label>
                    </ItemTemplate>
                </asp:TemplateField>
            </Columns>
        </asp:GridView>
        <asp:SqlDataSource ID="gvDataSource" runat="server" 
            ConnectionString="<%$ ConnectionStrings:ConnectionString %>" 
            DeleteCommand="DELETE FROM [WeekObjectiveStatus] WHERE [ID] = @ID" 
            InsertCommand="INSERT INTO [WeekObjectiveStatus] ([Objective], [WeekEnd], [ObjectiveStatus], [ObjectiveStatusComment]) VALUES (@Objective, @WeekEnd, @ObjectiveStatus, @ObjectiveStatusComment)" 
            SelectCommand="SELECT * FROM [WeekObjectiveStatus]" 
            UpdateCommand="UPDATE [WeekObjectiveStatus] SET [Objective] = @Objective, [WeekEnd] = @WeekEnd, [ObjectiveStatus] = @ObjectiveStatus, [ObjectiveStatusComment] = @ObjectiveStatusComment WHERE [ID] = @ID">
            <DeleteParameters>
                <asp:Parameter Name="ID" Type="Int32" />
            </DeleteParameters>
            <InsertParameters>
                <asp:Parameter Name="Objective" Type="String" />
                <asp:Parameter DbType="Date" Name="WeekEnd" />
                <asp:Parameter Name="ObjectiveStatus" Type="String" />
                <asp:Parameter Name="ObjectiveStatusComment" Type="String" />
            </InsertParameters>
            <UpdateParameters>
                <asp:Parameter Name="Objective" Type="String" />
                <asp:Parameter DbType="Date" Name="WeekEnd" />
                <asp:Parameter Name="ObjectiveStatus" Type="String" />
                <asp:Parameter Name="ObjectiveStatusComment" Type="String" />
                <asp:Parameter Name="ID" Type="Int32" />
            </UpdateParameters>
        </asp:SqlDataSource>
    </div>
    </form>
</body>
</html>
 
ProjectSurveyGrid.aspx.vb:
 
 
Partial Class ProjectSurveyGrid
    Inherits System.Web.UI.Page
 
    Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView1.RowDataBound
        If e.Row.RowType = DataControlRowType.DataRow Then
            Dim hfStatus As HiddenField = CType(e.Row.FindControl("hfStatus"), HiddenField)
            Dim rblStatus As RadioButtonList = CType(e.Row.FindControl("rblStatus"), RadioButtonList)
            rblStatus.SelectedValue = hfStatus.Value.ToString()
        End If
    End Sub
 
    Protected Sub rblStatusChanged(ByVal sender As Object, ByVal e As EventArgs)
        Dim hfStatus As HiddenField = CType(CType(CType(sender, RadioButtonList).Parent, DataControlFieldCell).Parent, GridViewRow).FindControl("hfStatus")
        hfStatus.Value = CType(sender, RadioButtonList).SelectedValue
    End Sub
 
    Protected Sub GridView1_RowUpdating(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewUpdateEventArgs) Handles GridView1.RowUpdating
        Dim rblStatus As RadioButtonList = CType(GridView1.Rows(e.RowIndex).FindControl("rblStatus"), RadioButtonList)
        If Not rblStatus.SelectedValue = "Green" Then
            Dim txtObjectiveStatusComment As TextBox = CType(GridView1.Rows(e.RowIndex).FindControl("txtObjectiveStatusComment"), TextBox)
            If Not txtObjectiveStatusComment.Text.Length > 0 Then
                'logic to handle the validaton
                e.Cancel = True
                txtObjectiveStatusComment.Focus()
                'Exit Sub
            End If
        End If
    End Sub
End Class

Open in new window

SurveyGrid.png

Author

Commented:
This is very close,  I updated the connection string to
            ConnectionString="<%$ ConnectionStrings:NovumDataConnectionString %>"
This gives the historical status of all tasks.

I need to be able to add new updates for each objective.

I was looking for the ability to provide one row for each Objectrive and the manager would enter the WeekEnd Date (drop down from a field WeekEnd in the table WeekEnding), ObjectiveStatus (the RadioButtonList) and ObjectiveStatusComment if the ObjectiveStatus is not = Green.

There is another table called Objective with a field also called Objective.  These values are unique and are what need to be updated on a weekly basis.
Hi,

Well, first of all, EE is not a shopping place for complete solutions! I have given you a fair amount of explanatory code and you should be able to continue working from here. Secondly, the requirements you state in your last comment does not correspond to those in your first post. I have covered what you stated as basic requirements, i.e:

- Databinding to a RadioButtonList
- Conditional checking of the comments upon updating
- Support for editing / updating the status of objectives

I suggest you try for yourself in order to learn. If you don't agree, have EE highlight your question.

/Carl.

Author

Commented:
Thank you for your assistance.  You are right.  

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial