C# 不,我需要它吗?我如何构造它? using System; using System.Collections.Generic; using System.Configuration; using System.Data; using System.Data
C# 不,我需要它吗?我如何构造它? using System; using System.Collections.Generic; using System.Configuration; using System.Data; using System.Data,c#,javascript,jquery,asp.net,signalr,C#,Javascript,Jquery,Asp.net,Signalr,不,我需要它吗?我如何构造它? using System; using System.Collections.Generic; using System.Configuration; using System.Data; using System.Data.SqlClient; using System.Linq; using System.Web; using Microsoft.AspNet.SignalR; using Microsoft.AspNet.SignalR.Hubs; ///
不,我需要它吗?我如何构造它?
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using Microsoft.AspNet.SignalR;
using Microsoft.AspNet.SignalR.Hubs;
/// <summary>
/// Summary description for RefreshHub
/// </summary>
namespace mytestSignalR
{
[HubName("refresh")]
public class RefreshHub : Hub
{
string filename;
[HubMethodName("update")]
public void UpdatePage()
{
string conn = @"Server=(LocalDb)\v11.0;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\Windblow.mdf";
SqlConnection connection = new SqlConnection(conn);
SqlDataReader dr;
connection.Open();
// string sql = "INSERT INTO [ProfileTab]([ID],[Name],[Address],[Age],[Occupation],[Nationality]) Values('" + TextBox1.Text + "','" + TextBox2.Text + "','" + TextBox3.Text + "','" + TextBox4.Text + "','" + TextBox5.Text + "','" + TextBox6.Text + "' ) ";
string sql = "Select * From [ImageTab] ";
SqlCommand cmd = new SqlCommand(sql, connection);
cmd.CommandType = CommandType.Text;
dr = cmd.ExecuteReader();
while (dr.Read())
{
filename = dr.GetString(0);
}
dr.Close();
connection.Close();
IHubContext context = GlobalHost.ConnectionManager.GetHubContext<RefreshHub>();
context.Clients.All.Databind(filename);
}
}
}
<script src="http://code.jquery.com/jquery-1.8.2.min.js" type="text/javascript"></script>
<script src="~/Scripts/jquery-1.6.4-vsdoc.js"></script>
<script src="~/Scripts/jquery-1.6.4.js"></script>
<script src="~/Scripts/jquery-1.6.4.min.js"></script>
<script src="~/Scripts/jquery.signalR-2.0.3.js"></script>
<script src="~/Scripts/jquery.signalR-2.0.3.min.js"></script>
<script type="text/javascript" src="~/signalr/hubs"></script>
<script type ="text/javascript" >
$(function () {
var page = $.connection.refreshHub;
// $lview = $("#ListView1");
page.client.databind = function (filename) {
// $lview = $("#ListView1");
$("#ListView1").bind(filename);
// $lview.bind(filename);
};
$.connection.hub.start().done(function () {
page.server.updatePage();
});
});
</script>
<button id="btnGridPopulator">Bind grid</button>
<table id="myClientGridView">
<colgroup>
<col width="100px" />
<col width="200px" />
</colgroup>
<tr>
<th>ID</th>
<th>Title</th>
</tr>
</table>
$(function() {
$("#btnGridPopulator").click(bindGrid);
});
function bindGrid() {
// here I'll simulate a message, as if it came from your SignalR
onmessage('[{"id":0,"title":"My videos"},{"id":1,"title":"My images"},{"id":2,"title":"My documents"}]');
}
function onmessage(msg)
{
var arr = JSON.parse(msg);
for(var i = 0; i < arr.length; i++) {
$("#myClientGridView").append("<tr><td>" + arr[i].id + "</td><td>" + arr[i].title + "</td></tr>");
}
}
// var page = $.connection.refreshHub;
var page = $.connection.refresh;
// page.server.updatePage();
page.server.update();