在这里,我创建了示例 从http://jqueryui.com/resources/download/jquery-ui-1.10.3.zip
下载示例
包括所有必需的资源,例如从演示到您的项目中的 jquery、CSS、图像等
<%@ Page Title="" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true"
CodeBehind="WebForm2.aspx.cs" Inherits="TestSf.WebForm2" %>
<%@ Register Src="SliderControl.ascx" TagName="SliderControl" TagPrefix="uc1" %>
<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<asp:GridView runat="server" ID="grd" AutoGenerateColumns="False">
<Columns>
<asp:BoundField DataField="ID" HeaderText="ID" SortExpression="ID" />
<asp:BoundField DataField="Name" HeaderText="Name" SortExpression="Name" />
<asp:BoundField DataField="MaxValue" HeaderText="MaxValue" SortExpression="MaxValue" />
<asp:TemplateField HeaderText="Slider">
<ItemTemplate>
<uc1:SliderControl ID="SliderControl1" runat="server" ctrlID='<%# Eval("ID") %>'
Maxvalue='<%# Eval("MaxValue") %>' Value='<%# Eval("Value") %>' />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
<script type="text/javascript">
if(arr.indexOf($(this).val())>-1)
{
alert('This is already selected , please select other option');
return false;
}
</script>
</asp:Content>
c# 示例代码
public partial class WebForm2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
List<TestMax> lst = new List<TestMax>();
lst.Add(new TestMax() { ID = 1, MaxValue = 10, Value = 4, Name = "Sandeep" });
lst.Add(new TestMax() { ID = 2, MaxValue = 12, Value = 3, Name = "Nilesh" });
lst.Add(new TestMax() { ID = 3, MaxValue = 11, Value = 6, Name = "Jayesh" });
grd.DataSource = lst;
grd.DataBind();
}
}
public class TestMax
{
public int ID { get; set; }
public string Name { get; set; }
public int MaxValue { get; set; }
public int Value { get; set; }
}
创建一个新的 USerControl 并使用这个标记
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="SliderControl.ascx.cs"
Inherits="TestSf.SliderControl" %>
<script>
$(function () {
$("#slider-range-max<%= ctrlID %>").slider({ range: "max", min: 1, max: <%= Maxvalue %>,
value: <%= Value %>, slide: function (event, ui) { $("#amount<%= ctrlID %>").val(ui.value); }
});
$("#amount<%= ctrlID %>").val($("#slider-range-max<%= ctrlID %>").slider("value"));
});
</script>
<div id="slider-range-max<%= ctrlID %>">
</div>
<input type="text" id="amount<%= ctrlID %>" style="border: 2; color: #f6931f; font-weight: bold;" />
用户控件 C# 代码
public partial class SliderControl : System.Web.UI.UserControl
{
protected void Page_Load(object sender, EventArgs e)
{
}
public int ctrlID { get; set; }
public int Maxvalue { get; set; }
public int Value { get; set; }
}