0

-- 我正在使用 asp.net 创建一个 gridview 控件,我想在设置为预定义值的列中添加一个 jquery 滑块。我的方法是使用gridview的行创建事件来调用具有预定义值的滑块函数,但是当页面呈现时没有滑块。关于为什么的任何想法?

  <%@ Page Title="" Language="vb" AutoEventWireup="false" MasterPageFile="~/Site.Master" CodeBehind="AssessmentLoggedIn.aspx.vb" Inherits="BCEE_KAIV2.WebForm1" %>
<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="server">
    <!-- HTTP 1.1 -->
<meta http-equiv="Cache-Control" content="no-store"/>
<!-- HTTP 1.0 -->
<meta http-equiv="Pragma" content="no-cache"/>
<!-- Prevents caching at the Proxy Server -->
<meta http-equiv="Expires" content="0"/>
    <style type="text/css">
        .btnHolder {
            text-align: center;
            width: 175px;
            margin: 0 auto;

        }
    #slider {
        float: left;
        width: 305px;
        padding-left:10px;
        padding-right:10px;
    }
     .auto-style3 {
         color:Gray;
     }
 </style>
    <link href="Styles/jquery-ui.css" rel="stylesheet" type="text/css" />
    <script type="text/javascript" src="Scripts/tinybox2/tinybox.js"></script>
    <link href="Scripts/tinybox2/style.css" rel="stylesheet" />
    <script src="Scripts/jquery-1.9.1.min.js" type="text/javascript"></script>
    <script src="Scripts/jquery-ui.js" type="text/javascript"></script>
    <script type="text/javascript">
        $(function () {
            $("#accordion").accordion({
                collapsible: true,
                heightStyle: "content"
            });
        });
    </script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
    <h3> <span class="auto-style3">Welcome</span>&nbsp;
    <asp:Label ID="lastNameHolder" runat="server" Text="Label" CssClass="auto-style3"></asp:Label>,
    &nbsp; 
    <asp:Label ID="firstNameHolder" runat="server" Text="Label" CssClass="auto-style3"></asp:Label>
    </h3>
    <div id="accordion">
        <h3>Step 1: Complete Optional Information</h3>
    <div>Displ some box <br /></div>
    <h3>Step 2: Take Assessment</h3>
    <div id="divStep2" runat="server"><div class="btnHolder"><asp:Button ID="btnAssessStart" runat="server" Text="Start Your Assessment" /></div></div>
    <h3>Step 3: Review Responses</h3>
    <div>
           <asp:LinqDataSource ID="linqDSUserResponse" runat="server" 
            ContextTypeName="BCEE_KAIV2.kaiDataContext" EntityTypeName="" 
            TableName="tblAssessmentQuestions">
        </asp:LinqDataSource>

        <asp:GridView ID="gvDisplayUserResponse" runat="server" 
            AutoGenerateColumns="False" DataKeyNames="questionPK" 
            DataSourceID="linqDSUserResponse">
            <Columns>
                <asp:CommandField ShowSelectButton="True" />
                <asp:TemplateField>
                    <ItemTemplate>
                        <asp:Label ID="lblItemNum" runat="server" Text="Label"></asp:Label>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="questionPK" SortExpression="questionPK" 
                    Visible="False">
                    <ItemTemplate>
                        <asp:Label ID="Label1" runat="server" Text='<%# Bind("questionPK") %>'></asp:Label>
                    </ItemTemplate>
                    <EditItemTemplate>
                        <asp:Label ID="Label1" runat="server" Text='<%# Eval("questionPK") %>'></asp:Label>
                    </EditItemTemplate>
                </asp:TemplateField>
                <asp:BoundField DataField="questionPresentationOrder" HeaderText="questionPresentationOrder" 
                    SortExpression="questionPresentationOrder" Visible="False" 
                    InsertVisible="False" />
                <asp:BoundField DataField="questionChoice1Text" 
                    HeaderText="questionChoice1Text" 
                    SortExpression="questionChoice1Text" />
                <asp:TemplateField>
                <ItemTemplate>
                    <div id="slider"> </div>
                </ItemTemplate>
                </asp:TemplateField>
                <asp:BoundField DataField="questionChoice2Text" 
                    HeaderText="questionChoice2Text" SortExpression="questionChoice2Text" />
                <asp:CheckBoxField DataField="questionStatus" HeaderText="questionStatus" 
                    SortExpression="questionStatus" Visible="False" />
            </Columns>
        </asp:GridView>
    </div>
    <h3>Step 4: Evaluate Assessment</h3>
        <div><div class="btnHolder"><asp:Button  ID="evaluateAssessment" runat="server" Text="Evaluate Your Assessment"/></div></div>
</div>
<script type="text/javascript">
         function open_win() {
             window.open("AssessmentLoggedIn.aspx", "_self");
         }
</script>

    </asp:Content>

和我背后的代码

Protected Sub gvDisplayUserResponse_RowCreated(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles gvDisplayUserResponse.RowCreated

    If e.Row.RowType = DataControlRowType.DataRow Then

        Dim myUserID As String = "13-zTest1RaffertyRichard0000"
        Dim myRowNumLabel As Label = CType(e.Row.Cells(1).Controls(1), Label)
        Dim myQuestionID As Guid = New Guid(gvDisplayUserResponse.DataKeys(e.Row.RowIndex).Value.ToString)

        myRowNumLabel.Text = e.Row.RowIndex.ToString() + 1

        Dim cxt As kaiDataContext = New kaiDataContext

        Dim myUserInput = From ui In cxt.tblAssesseeResults
                        Where ui.assesseeUniqueID = myUserID And
                              ui.assesseeQuestionID = myQuestionID
                        Select ui.assesseeResponseScore

        Dim mySliderValue As Integer = 0

        For Each mui In myUserInput
            mySliderValue = CType(mui, Integer)
        Next

        Dim csname As String = "userResponseSlider"
        Dim cstype As Type = Me.GetType()
        Dim cs As ClientScriptManager = Page.ClientScript

        If (Not cs.IsClientScriptBlockRegistered(cstype, csname)) Then
            Dim sb As New StringBuilder()

            sb.Append("(function () {")
            sb.Append("$('#slider').slider({")
            sb.Append("value: ")
            sb.AppendFormat("{0}", mySliderValue)
            sb.Append(", min: 10, max: 90, step: 1")
            sb.Append(" }); }); ")
            cs.RegisterStartupScript(cstype, csname, sb.ToString(), True)
        End If
    End If


End Sub
4

1 回答 1

0

首先,key参数 inRegisterStartupScript是唯一的,因此如果为多行调用此代码,则实际上只会将第一个脚本块呈现到页面。

我不认为这是你的主要问题。打开您的 javascript 控制台并查找错误,并查看页面的源代码并确保您确实有 1) id 为“slider”的 div 和 2) 用于呈现页面上呈现的滑块的客户端脚本。

于 2013-04-10T19:05:00.473 回答