我有一个gridview,我想使用javascript数组将每个gridview行的用户权限传递给客户端,我在gridview行数据绑定事件中编写下面的代码:
permissions+= "var permissions = [";
lbtnSendToApprove.Enabled = CheckPermission(document, project, user, null, eProjectAdminPermission.EditDocument);
if (!lbtnSendToApprove.Enabled)
{
lbtnSendToApprove.OnClientClick = string.Empty;
permissions += "Base64.encode('0' ) ,";
}
else
permissions += "Base64.encode('1' ) ,";
lbtnReleaseDocument.Enabled = true;
permissions += "Base64.encode('1' ) ,";
lbtnAddSubversion.Enabled = CheckPermission(document, project, user, null, eProjectAdminPermission.EditDocument);
if (!lbtnAddSubversion.Enabled)
{
lbtnAddSubversion.OnClientClick = string.Empty;
permissions += "Base64.encode('0' ) ,";
}
else
permissions += "Base64.encode('1' ) ,";
bool attachmentPermission = CheckPermission(document, project, user, null, eProjectAdminPermission.DetermineAttachment);
if (!attachmentPermission)
{
permissions += "Base64.encode('0' ) ];";
}
else
permissions += "Base64.encode('1' ) ];";
ScriptManager.RegisterClientScriptBlock(e.Row, e.Row.GetType(), "ContextMenuPermission", permissions , true);
但是这段代码只保留最后一行的值。我每行可以有这个数组吗?以及如何从gridview行索引中读取此数组?
答案 0 :(得分:0)
您可以尝试从数据源获取用户权限,比尝试从gridview获取权限更容易,然后向客户发送相同的" RegisterClientScriptBlock"
或者您可以将它们应用于应用于gridview的相同客户端选择器样式,假设"用户"你可以调用你的gridview可以用jquery
来做$ ('# users input tr [id ^ = permission]')
并且可以获得gridview的所有行,你可以使用for循环进行操作..
使用数据集的数据源是什么?
答案 1 :(得分:0)
好的,我用以下方式解决了我的问题:
首先我在javascript中定义一个数组:(一个二维数组):
var permissions=[];
然后我将我的rowDataBound代码更改为:
permissions += "permissions.push([";
lbtnSendToApprove.Enabled = CheckPermission(document, project, user, null, eProjectAdminPermission.EditDocument);
if (!lbtnSendToApprove.Enabled)
{
lbtnSendToApprove.OnClientClick = string.Empty;
permissions += "Base64.encode('0' ) ,";
}
else
permissions += "Base64.encode('1' ) ,";
lbtnReleaseDocument.Enabled = true;
permissions += "Base64.encode('1' ) ,";
lbtnAddSubversion.Enabled = CheckPermission(document, project, user, null, eProjectAdminPermission.EditDocument);
if (!lbtnAddSubversion.Enabled)
{
lbtnAddSubversion.OnClientClick = string.Empty;
permissions += "Base64.encode('0' ) ,";
}
else
permissions += "Base64.encode('1' ) ,";
bool attachmentPermission = CheckPermission(document, project, user, null, eProjectAdminPermission.DetermineAttachment);
if (!attachmentPermission)
{
permissions += "Base64.encode('0' ) ]);";
}
else
permissions += "Base64.encode('1' ) ]);";
ScriptManager.RegisterStartupScript(upDocuments, upDocuments.GetType(),"ContextMenuPermission"+e.Row.RowIndex.ToString(), permissions , true);//set permissions
在契约中我为所有行添加了行权限的数组。 现在我可以基于gridview的rowIndex获得每一行权限。例如,permissions [0]是指第一行权限。