请尝试使用以下代码片段。让我知道是否有任何问题。
JS
<script type="text/javascript">
function OPenPopuP(id, name, serverPath) {
var targetfile = serverPath + "/Allegati/" + id + "/" + name;
var openWnd = radopen(targetfile, "RadWindowDetails");
return false;
}
</script>
ASPX
<telerik:RadScriptManager ID="RadScriptManager1" runat="server">
</telerik:RadScriptManager>
<telerik:RadWindowManager ID="RadWindowManager1" runat="server">
</telerik:RadWindowManager>
<telerik:RadGrid ID="RadGrid1" runat="server" AutoGenerateColumns="false" OnNeedDataSource="RadGrid1_NeedDataSource"
OnItemDataBound="RadGrid1_ItemDataBound">
<MasterTableView CommandItemDisplay="Top" DataKeyNames="ID,FileName">
<Columns>
<telerik:GridBoundColumn DataField="ID" UniqueName="ID" HeaderText="ID">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="Name" UniqueName="Name" HeaderText="Name">
</telerik:GridBoundColumn>
<telerik:GridTemplateColumn>
<ItemTemplate>
<asp:Button ID="Button1" runat="server" />
</ItemTemplate>
<EditItemTemplate>
<asp:Button ID="Button1" runat="server" />
</EditItemTemplate>
</telerik:GridTemplateColumn>
<telerik:GridEditCommandColumn>
</telerik:GridEditCommandColumn>
</Columns>
</MasterTableView>
</telerik:RadGrid>
ASPX.CS
protected void RadGrid1_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
{
dynamic data1 = new[] {
new { ID = 1, Name ="Name_1",FileName = "jayesh-Softweb.jpg"},
new { ID = 2, Name = "Name_2",FileName = "jayesh-Softweb.jpg"},
new { ID = 3, Name = "Name_3",FileName = "jayesh-Softweb.jpg"},
new { ID = 4, Name = "Name_4",FileName = "jayesh-Softweb.jpg"},
new { ID = 5, Name = "Name_5",FileName = "jayesh-Softweb.jpg"}
};
RadGrid1.DataSource = data1;
}
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
{
if (e.Item is GridDataItem)
{
GridDataItem item = e.Item as GridDataItem;
string strID = item.GetDataKeyValue("ID").ToString();
string strFileName = item.GetDataKeyValue("FileName").ToString();
Button Button1 = item.FindControl("Button1") as Button;
Button1.Attributes.Add("onclick", "return OPenPopuP('" + strID + "','" + strFileName + "','" + Request.Url.GetLeftPart(UriPartial.Authority) + Request.ApplicationPath + "');");
}
else if (e.Item.IsInEditMode && e.Item is GridEditableItem)
{
GridEditableItem item = e.Item as GridEditableItem;
string strID = item.GetDataKeyValue("ID").ToString();
string strFileName = item.GetDataKeyValue("FileName").ToString();
Button Button1 = item.FindControl("Button1") as Button;
Button1.Attributes.Add("onclick", "return OPenPopuP('" + strID + "','" + strFileName + "','" + Request.Url.GetLeftPart(UriPartial.Authority) + Request.ApplicationPath + "');");
}
}