好吧,这让我今天疯了.所以我有以下标记:
<asp:ListView ID="lvComments" DataKeyNames="Id, Sender, Likes" runat="server">
<EmptyDataTemplate>
Run Code Online (Sandbox Code Playgroud)
等等...
假设我添加了一个标签:
<asp:Label ID="foo" Text='<%# Eval("Id") %>' runat="server"></asp:Label>
这将返回正确的DataKey"Id".现在在CodeBehind我正在做以下事情:
protected void CommentUp_Click(object sender, EventArgs e)
{
LinkButton CommentUp = (LinkButton)sender;
ListViewItem CommentItem = CommentUp.NamingContainer as ListViewItem;
ListView lvComments = (ListView)CommentItem.NamingContainer;
int i = (Int32)lvComments.DataKeys[CommentItem.DisplayIndex].Values["Id"];
}
Run Code Online (Sandbox Code Playgroud)
但是,我返回'86'一个整数,它不存在于来自DataSource的"Id"(如下所示).这个ListView嵌套在另一个ListView中,我在其父级上使用相同的技术来获取DataKey并且它正在工作......我也做了很多次.我无法弄清楚为什么这不会返回正确的Id整数.
如果有帮助,这就是我填充数据的方式:
public static List<Comment> GetAll(Int32 StreamId)
{
const string sqlString =
"SELECT * FROM Comments WHERE StreamId = @StreamId;";
List<Comment> list = new List<Comment>();
SqlConnection sqlConnection = taaraf.GetConn();
using (SqlCommand sqlCommand = new …Run Code Online (Sandbox Code Playgroud) 我有以下简单 <textarea>
<textarea id="streamWriter" rows="1" cols="20" placeholder="Writer"></textarea>
Run Code Online (Sandbox Code Playgroud)
我还有以下jQuery/JavaScript代码块:
$('textarea#streamWriter').keydown(function (e) {
if (e.keyCode == 13) {
if (e.ctrlKey) {
alert('ctrl enter - go down a line as normal return would');
return true;
}
e.preventDefault();
alert('submit - not your default behavior');
}
});
Run Code Online (Sandbox Code Playgroud)
我试图强制不要在正常的返回keydown上创建新的换行符.但是如果键入Ctrl + Enter,我想要这种行为.
这确实检测到了差异,但并没有强制我需要的行为.如果您使用过Windows Live Messenger,我需要相同的文本框行为.输入提交(在我的情况下,我将调用一个函数,但停止textarea下线)和Ctrl + Enter下一行.
解决方案?谢谢.
$('textarea#streamWriter').keydown(function (e) {
if (e.keyCode == 13) {
if (e.ctrlKey) {
//emulate enter press with a line break here.
return true;
}
e.preventDefault();
$('div#writerGadgets input[type=button]').click();
}
});
Run Code Online (Sandbox Code Playgroud)
以上就是我想要做的.只有部分模拟输入按下换行符.如果您知道,请告诉我如何做到这一点.
通常我会这样做来显示数据:
<%# Eval("string") %>如果数据源不是类型字符串数组,这将起作用.由于Eval方法没有表达式.我该如何显示数据?
ASPX
<ItemTemplate>
<%# Eval("") %>
</ItemTemplate>
Run Code Online (Sandbox Code Playgroud)
代码隐藏:
string[] images = Directory.GetFiles(UploadsPath);
lvSlideShow.DataSource = images;
lvSlideShow.DataBind();
Run Code Online (Sandbox Code Playgroud) 所以我使用SignalR,它在我的网站上设置并正常工作.
假设用户A登录(我正在使用Membership API).当A登录时,我正在调用位于我的母版页中的.js的连接.这将为此用户分配一个特定的userId.
假设现在用户B登录进行某些事件,该事件需要通过代码隐藏通知用户A.
所以我在这里尝试做的是通知用户B使用CodeBehind的A动作.用户B如何知道用户A的ID以及整个过程如何工作?我在文档中找不到帮助,因为它没有涉及到那种东西.
怎么能实现这一目标?谢谢.
为什么尝试设置时,我得到一个无效转换异常NULL从数据库里面的返回值Comments是类型Int32.
我想替换这个:
try
{
objStreamItem.Comments = (Int32)sqlReader["Comments"];
if (objStreamItem.Comments > 0) {
listComments = Comment.GetAll(objStreamItem.Id);
}
}
catch (InvalidCastException)
{
// Execute if "Comments" returns NULL
listComments = null;
objStreamItem.Comments = 0;
}
Run Code Online (Sandbox Code Playgroud)
有了这个:
Comments = ((Int32?)sqlReader["Comments"]) ?? 0
Run Code Online (Sandbox Code Playgroud)
这两者在不同的背景下,但你应该得到这个想法.我试图以更优雅的方式解决这个问题,而不是使用try catch块.
谢谢.
它作为可空整数存储在数据库中.
public int? Comments
{
get;
set;
}
Run Code Online (Sandbox Code Playgroud)
我有这个
WITH sequenced_records AS (
SELECT ROW_NUMBER() OVER (ORDER BY [DateTime] DESC) AS sequence_id, *
FROM StreamView
WHERE TypeOf = @TypeOf
AND [DateTime] >= @DateTime
)
SELECT * FROM sequenced_records WHERE sequence_id = 1;
Run Code Online (Sandbox Code Playgroud)
哪个可以获得最新记录.但如果找不到什么呢?我怎样才能让它返回倒退的最新记录?意味着如果没有比给定DateTime更新的项目,它将反向返回并获取它找到的第一个项目.
谢谢
我有这个:
uint8_t key[] = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31};
如何将其转换为char或其他内容,以便可以阅读其内容?这是我用于使用AES加密数据的密钥。
感谢帮助。谢谢
为什么这会无限期地运行而不是添加天数
var startDate = new DateTime(year, 1, 1);
var endDate = startDate.AddYears(1);
while (startDate < endDate)
{
startDate.AddDays(1);
}
Run Code Online (Sandbox Code Playgroud)
目标是在一年中的所有日子里循环.
谢谢!
我有这个:
public getFriends() : IUser[] {
let friends: IUser[];
friends[0].Id = "test";
friends[0].Email = "asdasd";
return friends;
}
Run Code Online (Sandbox Code Playgroud)
听起来可能很愚蠢,但为什么我的朋友 [0] 未定义?如果在这种情况下我没有 User 类型的类,我该怎么办。
发现了一篇关于使用jQuery来使用代码隐藏WebMethod的精彩文章.我想在我的网站上应用它.但我一直得到以下错误,虽然我确保参数名称是相同的.
$(".StreamLike").live("mouseover", function () {
var Id = $(this).parent().parent().find(".StreamIndex").html();
alert(Id);
$.ajax({
type: 'POST',
url: 'Default.aspx/GetLikes',
data: { "Id": Id },
contentType: 'application/json; charset=utf-8',
dataType: 'json',
success: LikesSuccess,
error: LikesError
});
});
function LikesSuccess(result, userContext, methodName) {
for (var i in result) {
alert(result[i]);
}
Run Code Online (Sandbox Code Playgroud)
的WebMethod:
[WebMethod]
public static string[] GetLikes(int Id)
{
List<Like> Likes = Like.GetById(Id, false);
string[] Senders = new string[Likes.Count];
for (int i = 0; i < Likes.Count; i++)
{
Senders[i] = Likes[i].Sender;
}
return Senders;
}
Run Code Online (Sandbox Code Playgroud)
完整的错误消息如下: …
你认为这是一种检索通知的坏方法吗?这个WebMethod将通过JavaScript每10秒调用一次.有没有更好的方法呢?如果是这样请详细说明.谢谢.
[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public int[] GetNotifications()
{
int[] Notifications = new int[3]{0, 0, 0};
if (HttpContext.Current.User.Identity.IsAuthenticated) {
string UserName = HttpContext.Current.User.Identity.Name;
Notifications[0] = Notification.GetAll(UserName, false).Count;
Notifications[1] = Message.GetAll(UserName, false).Count;
Notifications[2] = Friendship.GetFriends(UserName, true).Count;
}
return Notifications;
}
Run Code Online (Sandbox Code Playgroud) 假设我有以下对象foo及其属性,如下所示:
class foo
public string name
public string property1
public string property2
Run Code Online (Sandbox Code Playgroud)
现在让我们实例化两个列表foo:List<foo>()
第一个列表包含两个foo对象:
new foo() =
{
name = "name",
property1 = "random value",
property1 = "random value"
}
new foo() =
{
name = "name",
property1 = "random value",
property1 = "random value"
}
Run Code Online (Sandbox Code Playgroud)
第二个列表包含一个foo对象:
new foo() =
{
name = "name",
property1 = "random value",
property1 = "random value"
}
Run Code Online (Sandbox Code Playgroud)
是否可以使用LINQ来比较并返回一个List<foo> …
c# ×9
asp.net ×7
.net ×4
javascript ×3
ajax ×2
jquery ×2
listview ×2
sql-server ×2
asmx ×1
c++ ×1
comet ×1
html ×1
json ×1
linq ×1
list ×1
signalr ×1
sql ×1
typescript ×1
webmethod ×1
while-loop ×1