I am trying to construct something similar to (but different from) one of your demos located in https://demos.telerik.com/aspnet-ajax/controls/examples/integration/gridandwindow/defaultcs.aspx?product=window , but am having issues.
When I follow (or at least think I am following) the demo code and reproduce it as best I can for my use, the template column always comes up disabled somehow and there is no activity when I click on it. A screen capture of the resulting grid is attached.
My applicable code is shown in the snippets below. Any pointers you can give me would be appreciated. Obviously I've gotten something really wrong. The object of my code is to create a column that, when clicked, executes a javascript function called enterit(recno) but right now the code is trying to execute the ShowEditForm function (but I don't really want it to display an edit form within the grid).
Javascript functions are:
The grid/template column is defined as:
The RadGrid1_ItemCreated is:
The grid is programmatically defined in Page_Init as shown below. Please ignore the hypercolumn defined programmatically -- that is what I trying NOT to use. I just haven't removed it yet.
I think that is all the affected code should need to see. If there's anything else, please let me know. Sorry to be a pain!
Thanks in advance!
Lynn
When I follow (or at least think I am following) the demo code and reproduce it as best I can for my use, the template column always comes up disabled somehow and there is no activity when I click on it. A screen capture of the resulting grid is attached.
My applicable code is shown in the snippets below. Any pointers you can give me would be appreciated. Obviously I've gotten something really wrong. The object of my code is to create a column that, when clicked, executes a javascript function called enterit(recno) but right now the code is trying to execute the ShowEditForm function (but I don't really want it to display an edit form within the grid).
Javascript functions are:
<
asp:Content
ID
=
"Content1"
ContentPlaceHolderID
=
"HeadContent"
runat
=
"server"
>
<
telerik:RadCodeBlock
ID
=
"RadCodeBlock1"
runat
=
"server"
>
<
script
type
=
"text/javascript"
>
function enterit(recno) {
document.getElementById('<%= K.ClientID%>').value = recno;
document.getElementById('<%= KI.ClientID%>').value = recno;
document.getElementById('<%= KII.ClientID%>').value = recno;
document.getElementById('<%= M.ClientID%>').value = "Y";
document.getElementById('<%= MI.ClientID%>').value = "N";
document.getElementById('<%= MII.ClientID%>').value = "N";
document.forms["form1"].submit();
}
function makeNew(sender, eventArgs) {
document.getElementById('<%= HiddenField1.ClientID%>').value = "myTarget;
document.getElementById('<%= K.ClientID%>').value = "0";
document.getElementById('<%= KI.ClientID%>').value = "0";
document.getElementById('<%= KII.ClientID%>').value = "0";
document.getElementById('<%= M.ClientID%>').value = "N";
document.getElementById('<%= MI.ClientID%>').value = "N";
document.getElementById('<%= MII.ClientID%>').value = "N";
document.forms["form1"].submit();
}
function ShowEditForm(id, rowIndex) {
var grid = $find("<%= RadGrid1.ClientID %>");
var rowControl = grid.get_masterTableView().get_dataItems()[rowIndex].get_element();
grid.get_masterTableView().selectItem(rowControl, true);
alert("My row's id value=" + id);
//window.radopen("EditForm_csharp.aspx?EmployeeID=" + id, "UserListDialog");
return false;
}
</
script
>
</
telerik:RadCodeBlock
>
</
asp:Content
>
The grid/template column is defined as:
<
telerik:RadGrid
ID
=
"RadGrid1"
runat
=
"server"
Width
=
"99.7%"
AutoGenerateColumns
=
"false"
AllowPaging
=
"false"
>
<
MasterTableView
AutoGenerateColumns
=
"False"
DataKeyNames
=
"MAB"
ClientDataKeyNames
=
"MAB"
Width
=
"100%"
>
<
Columns
>
<
telerik:GridTemplateColumn
UniqueName
=
"TemplateEditColumn"
>
<
ItemTemplate
>
<
asp:HyperLink
ID
=
"EditLink"
runat
=
"server"
Text
=
"Edit"
></
asp:HyperLink
>
</
ItemTemplate
>
</
telerik:GridTemplateColumn
>
</
Columns
>
</
MasterTableView
>
</
telerik:RadGrid
>
The RadGrid1_ItemCreated is:
protected
void
RadGrid1_ItemCreated(
object
sender, GridItemEventArgs e)
{
if
(e.Item
is
GridDataItem)
{
HyperLink editLink = (HyperLink)e.Item.FindControl(
"EditLink"
);
editLink.Attributes[
"href"
] =
"javascript:void({0});"
;
editLink.Attributes[
"onclick"
] = String.Format(
"return ShowEditForm('{0}');"
, e.Item.OwnerTableView.DataKeyValues[e.Item.ItemIndex][
"MAB"
], e.Item.ItemIndex);
}
}
The grid is programmatically defined in Page_Init as shown below. Please ignore the hypercolumn defined programmatically -- that is what I trying NOT to use. I just haven't removed it yet.
protected
void
Page_Init(
object
sender, System.EventArgs e)
{
GridHyperLinkColumn hypercolumn =
null
;
GridBoundColumn boundcolumn =
null
;
GridTemplateColumn tempcolumn =
null
;
RadGrid1.EnableViewState =
false
;
RadGrid1.NeedDataSource +=
new
Telerik.Web.UI.GridNeedDataSourceEventHandler(RadGrid1_NeedDataSource);
RadGrid1.ID =
"RadGrid1"
;
RadGrid1.PageSize = 15;
RadGrid1.AllowPaging =
true
;
RadGrid1.PagerStyle.Mode = GridPagerMode.NextPrevAndNumeric;
RadGrid1.AutoGenerateColumns =
false
;
RadGrid1.AllowFilteringByColumn =
false
;
RadGrid1.ExportSettings.ExportOnlyData =
true
;
RadGrid1.ExportSettings.IgnorePaging =
true
;
RadGrid1.ExportSettings.HideStructureColumns =
true
;
RadGrid1.ExportSettings.OpenInNewWindow =
true
;
RadGrid1.MasterTableView.CommandItemSettings.ShowExportToCsvButton =
false
;
RadGrid1.MasterTableView.CommandItemSettings.ShowExportToExcelButton =
false
;
RadGrid1.MasterTableView.CommandItemSettings.ShowExportToPdfButton =
false
;
RadGrid1.MasterTableView.CommandItemSettings.ShowExportToWordButton =
false
;
RadGrid1.MasterTableView.CommandItemSettings.ShowAddNewRecordButton =
false
;
RadGrid1.MasterTableView.CommandItemDisplay = GridCommandItemDisplay.None;
RadGrid1.MasterTableView.DataKeyNames =
new
string
[] {
"MAB"
};
hypercolumn =
new
GridHyperLinkColumn();
hypercolumn.HeaderText =
"Edit"
;
hypercolumn.UniqueName =
"MAB"
;
hypercolumn.Text =
"<img border=\"0\" alt=\"View\" src=\"../Icons/pencil_16.png\" />"
;
hypercolumn.DataNavigateUrlFields =
new
string
[] {
"MAB"
};
hypercolumn.DataNavigateUrlFormatString =
"OfcMABEdit.aspx?M=Y&K="
+
"{0}"
;
RadGrid1.MasterTableView.Columns.Add(hypercolumn);
boundcolumn =
new
GridBoundColumn();
this
.RadGrid1.Columns.Add(boundcolumn);
boundcolumn.UniqueName =
"MABName"
;
boundcolumn.DataField =
"MABName"
;
boundcolumn.HeaderText =
"Name"
;
boundcolumn.Visible =
true
;
boundcolumn =
null
;
RadGrid1.AllowPaging = Convert.ToBoolean(Session[
"ShowListsWithPaging"
]);
}
I think that is all the affected code should need to see. If there's anything else, please let me know. Sorry to be a pain!
Thanks in advance!
Lynn