I have the following in my .aspx file. When the user clicks on Edit, I like it to show a form where they can Update or Cancel. Currently when I click on Edit, it does nothing. Note that am handling the datasource from the code behind. As such, I do not have a DataSource within the .aspx file for the RadGrid:
Here is my code:
<telerik:RadGrid ID="rdClosedLoop" runat="server" GridLines="None" OnDeleteCommand="DeleteClosedLoop"
Skin="Metro" ActiveItemStyle-HorizontalAlign="Center" AutoGenerateEditColumn="true" >
<MasterTableView EditMode="EditForms" AutoGenerateColumns="False" DataKeyNames="ID" >
<RowIndicatorColumn>
<HeaderStyle Width="20px" />
</RowIndicatorColumn>
<ExpandCollapseColumn>
<HeaderStyle Width="20px" />
</ExpandCollapseColumn>
<Columns>
<telerik:GridBoundColumn DataField="ID" HeaderText="ID" SortExpression="ID" EditFormColumnIndex="0"
UniqueName="ID" HeaderStyle-HorizontalAlign="Center">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="ActiveInhibitor" HeaderText="ActiveInhibitor" SortExpression="ActiveInhibitor" EditFormColumnIndex="0"
UniqueName="ActiveInhibitor" HeaderStyle-HorizontalAlign="Center">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="Conductivity" HeaderText="Conductivity" SortExpression="Conductivity" EditFormColumnIndex="0"
UniqueName="Conductivity" HeaderStyle-HorizontalAlign="Center">
</telerik:GridBoundColumn>
<telerik:GridButtonColumn CommandName="Delete" Text="Delete" UniqueName="DeleteColumn">
</telerik:GridButtonColumn>
</Columns>
<EditFormSettings ColumnNumber="1" CaptionFormatString="Edit for ID {0}"
CaptionDataField="ID">
<FormTableItemStyle Wrap="False"></FormTableItemStyle>
<FormCaptionStyle CssClass="EditFormHeader"></FormCaptionStyle>
<FormMainTableStyle GridLines="None" CellSpacing="0" CellPadding="3" Width="100%">
</FormMainTableStyle>
<FormTableStyle GridLines="Horizontal" CellSpacing="0" CellPadding="2" CssClass="module"
Height="110px" Width="100%"></FormTableStyle>
<FormTableAlternatingItemStyle Wrap="False"></FormTableAlternatingItemStyle>
<FormStyle Width="100%" BackColor="#eef2ea"></FormStyle>
<EditColumn UpdateText="Update record" UniqueName="EditCommandColumn1" CancelText="Cancel edit">
</EditColumn>
<FormTableButtonRowStyle HorizontalAlign="Left" CssClass="EditFormButtonRow"></FormTableButtonRowStyle>
</EditFormSettings>
</MasterTableView>
<HeaderContextMenu CssClass="GridContextMenu GridContextMenu_Default" EnableImageSprites="True">
</HeaderContextMenu>
</telerik:RadGrid>
Code behind:
protected void btnClosedLoop_Click(object sender, EventArgs e)
{
// Note - verId is based on some conditions
var resultCLList = (from ms in db.ver_ClosedLoop
where ms.VerificationId == verId
select ms).ToList();
rdClosedLoop.DataSource = resultCLList;
rdClosedLoop.DataBind();
}
Please try with the below code snippet.
ASPX
<telerik:RadGrid ID="rdClosedLoop" runat="server" GridLines="None"
Skin="Metro" ActiveItemStyle-HorizontalAlign="Center" AutoGenerateEditColumn="true"
OnItemCommand="rdClosedLoop_ItemCommand">
<MasterTableView EditMode="EditForms" AutoGenerateColumns="False" DataKeyNames="ID">
<RowIndicatorColumn>
<HeaderStyle Width="20px" />
</RowIndicatorColumn>
<ExpandCollapseColumn>
<HeaderStyle Width="20px" />
</ExpandCollapseColumn>
<Columns>
<telerik:GridBoundColumn DataField="ID" HeaderText="ID" SortExpression="ID" EditFormColumnIndex="0"
UniqueName="ID" HeaderStyle-HorizontalAlign="Center">
</telerik:GridBoundColumn>
<telerik:GridButtonColumn CommandName="Delete" Text="Delete" UniqueName="DeleteColumn">
</telerik:GridButtonColumn>
</Columns>
<EditFormSettings ColumnNumber="1" CaptionFormatString="Edit for ID {0}" CaptionDataField="ID">
<FormTableItemStyle Wrap="False"></FormTableItemStyle>
<FormCaptionStyle CssClass="EditFormHeader"></FormCaptionStyle>
<FormMainTableStyle GridLines="None" CellSpacing="0" CellPadding="3" Width="100%">
</FormMainTableStyle>
<FormTableStyle GridLines="Horizontal" CellSpacing="0" CellPadding="2" CssClass="module"
Height="110px" Width="100%"></FormTableStyle>
<FormTableAlternatingItemStyle Wrap="False"></FormTableAlternatingItemStyle>
<FormStyle Width="100%" BackColor="#eef2ea"></FormStyle>
<EditColumn UpdateText="Update record" UniqueName="EditCommandColumn1" CancelText="Cancel edit">
</EditColumn>
<FormTableButtonRowStyle HorizontalAlign="Left" CssClass="EditFormButtonRow"></FormTableButtonRowStyle>
</EditFormSettings>
</MasterTableView>
<HeaderContextMenu CssClass="GridContextMenu GridContextMenu_Default" EnableImageSprites="True">
</HeaderContextMenu>
</telerik:RadGrid>
ASPX.CS
protected void Button1_Click(object sender, EventArgs e)
{
rdClosedLoop.DataSource = getDummyData(0);
rdClosedLoop.DataBind();
}
protected DataTable getDummyData(int verId)
{
// Note - verId is based on some conditions
DataTable dt = new DataTable();
dt.Columns.Add("ID",typeof(int));
dt.Rows.Add(1);
dt.Rows.Add(2);
dt.Rows.Add(3);
return dt;
}
protected void rdClosedLoop_ItemCommand(object sender, GridCommandEventArgs e)
{
if (e.CommandName == RadGrid.EditCommandName)
{
rdClosedLoop.DataSource = getDummyData(0);
rdClosedLoop.DataBind();
}
}
Let me know if any concern.
Related
My problem is that I have 2 radgrids on a page and I cannot filter the columns.
One table is created like this:
<asp:UpdatePanel ID="UpdatePanel2" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<div class="demo-container" id="demo-container">
<div class="gridPositioning">
<div>
<telerik:RadGrid ID="mdegGrid" runat="server"
AllowPaging="True" AllowCustomPaging="true"
AllowSorting="True"
AllowFilteringByColumn="True"
OnNeedDataSource="mdegGrid_NeedDataSource"
OnItemCommand="mdegGrid_ItemCommand"
OnItemCreated="mdegGrid_ItemCreated"
OnItemDataBound="mdegGrid_ItemDataBound"
OnPreRender="mdegGrid_PreRender"
CellSpacing="0" GridLines="None"
EnableLinqExpressions="false"
PageSize="12"
PagerStyle-AlwaysVisible="true"
EnableEmbeddedSkins="False"
Skin="_HBB"
CellPadding="0"
MasterTableView-CellSpacing="0" >
<GroupingSettings CaseSensitive="false" />
<MasterTableView AutoGenerateColumns="false" TableLayout="Auto" HierarchyLoadMode="ServerOnDemand"
DataKeyNames="ImportID" CommandItemDisplay="None" InsertItemPageIndexAction="ShowItemOnFirstPage">
<CommandItemSettings ShowRefreshButton="false" />
<RowIndicatorColumn FilterControlAltText="Filter RowIndicator column" Visible="True">
<HeaderStyle Width="20px" />
</RowIndicatorColumn>
<ExpandCollapseColumn FilterControlAltText="Filter ExpandColumn column" Visible="True">
<HeaderStyle Width="20px" />
</ExpandCollapseColumn>
<Columns>
<telerik:GridBoundColumn UniqueName="ImportID" HeaderText="<%$ Resources:HBS, Import_ID %>" DataField="ImportID_Filter"
SortExpression="ImportID"
FilterControlWidth="99%" ShowFilterIcon="false"
AutoPostBackOnFilter="true" CurrentFilterFunction="Contains">
<HeaderStyle ForeColor="Silver" Height="20px" Width="7%" HorizontalAlign="Left"></HeaderStyle>
<ItemStyle ForeColor="Gray" Height="20px" Width="7%" HorizontalAlign="Left"></ItemStyle>
</telerik:GridBoundColumn>
In the code behind in the mdeGrid_PreRender funtion I have the following code:
mdegGrid.MasterTableView.FilterExpression = string.Format("([{0}] LIKE N\'%{1}%\') ", _columnNameImports, txt.Text);
GridColumn column = mdegGrid.MasterTableView.GetColumnSafe(_columnNameImports);
column.CurrentFilterFunction = GridKnownFunction.Contains;
column.CurrentFilterValue = txt.Text;
mdegGrid.MasterTableView.Rebind();
UpdatePanel2.Update();
The problem is that nothing is happening. The grid becomes disabled with a Please wait loading message but after that, no filtering is happening.
I try using Rad Grid with web Api as data source
<telerik:RadGrid runat="server" ID="grdUsers" AllowPaging="true" AllowSorting="true"
AllowFilteringByColumn="true" PageSize="5">
<MasterTableView AutoGenerateColumns="False" DataKeyNames="Id" ClientDataKeyNames="Id,PasswordHash">
<PagerStyle Mode="NumericPages" AlwaysVisible="true" />
<Columns>
<telerik:GridImageColumn DataType="System.String" DataImageUrlFields="Image" AlternateText="User image"
UniqueName="Image"
ImageAlign="Middle" ImageHeight="50px" ImageWidth="50px" AllowFiltering="false" HeaderText="">
</telerik:GridImageColumn>
<telerik:GridBoundColumn DataField="UserName" HeaderText="User Name" UniqueName="UserName"
DataType="System.String">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="FullName" HeaderText="Name" UniqueName="FullName"
DataType="System.String">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="Email" HeaderText="Email" UniqueName="Email"
DataType="System.String">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="RegistrationDate" HeaderText="Registration Date" UniqueName="RegistrationDate"
DataFormatString="{0:dd/MM/yyyy}">
</telerik:GridBoundColumn>
<telerik:GridButtonColumn UniqueName="btnEdit" ButtonType="PushButton" Text="Edit" CommandName="Edit"></telerik:GridButtonColumn>
<telerik:GridButtonColumn UniqueName="btnDelete" ButtonCssClass="del" ButtonType="PushButton" Text="Delete" CommandName="Delete"></telerik:GridButtonColumn>
</Columns>
</MasterTableView>
<ClientSettings>
<Selecting AllowRowSelect="True" />
<ClientEvents OnCommand="RadGridCommand" />
<DataBinding Location="/SecuHostapi/Security/User/GetAll" ResponseType="JSON">
<DataService TableName="SecuHostUser" Type="OData" />
</DataBinding>
</ClientSettings>
</telerik:RadGrid>
Wep Api code
[HttpGet]
public List<SecuHostUser> GetAll(ODataQueryOptions<SecuHostUser> options)
{
UsersRep userRep = new UsersRep();
return userRep.GetAll();
}
although, I have put PageSize="5", the final result show all the data from the data base
This problem can be solved by returning a PageResult instead of a list.
[HttpGet]
public PageResult GetAll(ODataQueryOptions<SecuHostUser> options)
{
UsersRep userRep = new UsersRep();
//return userRep.GetAll();
var users = userRep.GetAll().AsQueryable();
var results = options.ApplyTo(users);
return new PageResult<SecuHostUser>(results as IEnumerable<SecuHostUser>,
Request.GetNextPageLink(), Request.GetInlineCount());
}
I'm trying to get RadGrid to conditionally hide or disable a field when it is in edit mode based on the value of another field.
I have been able to get this to work when the grid displays the list of items, but once the grid enters edit mode, the columns display ...
I am using OnItemDataBound to successfully conditionally display during the initial load, but setting the items when the user clicks a row to get it into batch mode is not working.
Note: PValue and CValue and in GridTemplateColumns, as is CardStatus.
public void RadGrid1_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e)
{
foreach (GridDataItem item in RadGrid1.Items)
{
string BoundColumnValue = item["CardStatus"].Text; // accessing GridBoundColumn value using ColumnUniqueName
string BoundColumnValue2 = item["CValue"].Text;
TextBox txtbx = (TextBox)item.FindControl("CardStatus");
Label numlb = (Label)item.FindControl("CardValue");
if (txtbx.Text.Equals("True"))
{
txtbx.ForeColor = Color.Red;
numlb.Enabled = false;
numlb.BackColor = Color.Yellow;
numlb.ForeColor = Color.Red;
//Just testing to see if it would evaluate
}
else
{
txtbx.ForeColor = Color.Beige;
}
//string TemplateColumnValue = lb.Text;// accessing Label Text.
}
foreach (GridEditableItem item in RadGrid1.EditItems)
{
string BoundColumnValue = item["CardStatus"].Text; // accessing GridBoundColumn value using ColumnUniqueName
string BoundColumnValue2 = item["CValue"].Text;
TextBox txtbx = (TextBox)item.FindControl("CardStatus");
if (txtbx.Text.Equals("True"))
{
txtbx.ForeColor = Color.Red;
//numTxt.BackColor = Color.Yellow;
//numTxt.ForeColor = Color.Red;
}
else
{
txtbx.ForeColor = Color.Beige;
}
}
}
I just need to be able to selectively prevent data entry in a column
The ASPX source is below:
<telerik:RadGrid ID="RadGrid1" runat="server" AllowAutomaticUpdates="true" Height="930px" DataSourceID="SqlDataSource4" CellSpacing="0" GridLines="None" Width="640px" OnItemDataBound="RadGrid1_ItemDataBound" OnItemCreated="RadGrid1_ItemCreated" OnBatchEditCommand="RadGrid1_BatchEditCommand1" Skin="WebBlue">
<ClientSettings>
<Scrolling AllowScroll="True" UseStaticHeaders="True" />
</ClientSettings>
<MasterTableView AutoGenerateColumns="False" EditMode="Batch" Width="620px" CommandItemDisplay="TopAndBottom" DataSourceID="SqlDataSource4" DataKeyNames="CountKey">
<CommandItemSettings ExportToPdfText="Export to PDF" ShowSaveChangesButton="true" ShowRefreshButton="false" ShowAddNewRecordButton="false"></CommandItemSettings>
<BatchEditingSettings OpenEditingEvent="Click" EditType="Row" />
<RowIndicatorColumn Visible="True" FilterControlAltText="Filter RowIndicator column">
<HeaderStyle Width="20px"></HeaderStyle>
</RowIndicatorColumn>
<ExpandCollapseColumn Visible="True" FilterControlAltText="Filter ExpandColumn column">
<HeaderStyle Width="20px"></HeaderStyle>
</ExpandCollapseColumn>
<EditFormSettings>
<EditColumn FilterControlAltText="Filter EditCommandColumn column"></EditColumn>
</EditFormSettings>
<PagerStyle PageSizeControlType="RadComboBox"></PagerStyle>
<Columns>
<telerik:GridBoundColumn DataField="Pcolumn" ItemStyle-Width="75px" ReadOnly="true" Visible="false" DataType="System.Int32" FilterControlAltText="Filter Pcolumn column" HeaderText="Pcolumn" SortExpression="Pcolumn" UniqueName="Pcolumn">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="Row" ReadOnly="true" Visible="false" DataType="System.Int32" FilterControlAltText="Filter Row column" HeaderText="Row" SortExpression="Row" UniqueName="Row">
</telerik:GridBoundColumn>
<telerik:GridTemplateColumn ColumnEditorID="PValue" HeaderText="Pattern" DataField="PValue" UniqueName="PValue" ItemStyle-Width="75px" HeaderStyle-Width="75px">
<EditItemTemplate>
<telerik:RadNumericTextBox ID="PValue" Width="50px" runat="server" MaxLength="1" MaxValue="9" NumberFormat-DecimalDigits="0" Text='<%# Bind("PValue") %>'></telerik:RadNumericTextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="PValue" ErrorMessage="<br/>Required (0-9) Only)!" SetFocusOnError="true"></asp:RequiredFieldValidator>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="PValue" Width="50px" runat="server" Text='<%# Bind("PValue") %>'></asp:Label>
</ItemTemplate>
</telerik:GridTemplateColumn>
<telerik:GridTemplateColumn ColumnEditorID="CValue" DataField="CValue" HeaderText="Card" UniqueName="CValue" ItemStyle-Width="75px" HeaderStyle-Width="75px">
<EditItemTemplate>
<telerik:RadNumericTextBox ID="CValue" Width="50px" AllowOutOfRangeAutoCorrect="false" runat="server" MaxLength="1" MaxValue="1" NumberFormat-DecimalDigits="0" Text='<%# Bind("CValue") %>'></telerik:RadNumericTextBox>
<asp:RequiredFieldValidator runat="server" ControlToValidate="CValue" ErrorMessage="<br />Required (0-1 Only)!" SetFocusOnError="true"></asp:RequiredFieldValidator>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="CValue" Width="50px" runat="server" Text='<%# Bind("CValue") %>'></asp:Label>
</ItemTemplate>
</telerik:GridTemplateColumn>
<telerik:GridBoundColumn DataField="DateEdited" ReadOnly="true" Visible="false" DataType="System.DateTime" FilterControlAltText="Filter DateEdited column" HeaderText="DateEdited" SortExpression="DateEdited" UniqueName="DateEdited">
</telerik:GridBoundColumn>
<telerik:GridTemplateColumn UniqueName="CardStatus" DataField="CardStatus" ItemStyle-Width="50px" HeaderStyle-Width="50px">
<ItemTemplate>
<asp:TextBox ID="CardStatus" Width="10px" runat="server" Text='<%# Bind("CardStatus") %>'></asp:TextBox>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="CardStatus" Width="10px" runat="server" Text='<%# Bind("CardStatus") %>'></asp:TextBox>
</EditItemTemplate>
</telerik:GridTemplateColumn>
</Columns>
</MasterTableView>
<PagerStyle PageSizeControlType="RadComboBox"></PagerStyle>
<FilterMenu EnableImageSprites="False"></FilterMenu>
</telerik:RadGrid>
Any help / workarounds would be appreciated ... again, "just" need to prevent editing in the CValue column when the CardStatus value is true (bit field) ... using batch mode (using another solution isn't an option now).
Thanks
Larry
Well, this doesn't answer the Telerik question, but ended up doing this with the MS GridView, using the tutorial here: http://msdn.microsoft.com/en-us/library/aa992036(v=vs.90).aspx.
Also was able to customize, and detect hidden grid fields, and hide cells (and disable validators) based on the hidden field's condition.
Added the following code in the RowDataBound event of the gridview:
DataRowView drv = (DataRowView)e.Row.DataItem;
if (drv["Status"].Equals(true))
{
// Find the order of the cell
e.Row.Cells[5].CssClass = "hiddencol"; // using the display: none style
// Find the Validator control in the template column
RequiredFieldValidator reqF = (RequiredFieldValidator)e.Row.Cells[5].FindControl("RequiredFieldValidator1");
reqF.Enabled = false;
}
else
{
}
I have a grid which has the CarrierID specified as the "DataKeyNames" which is also an invisible property in the grid.
I have a hyperlink column that when clicked should pass the value of the CarrierNetID (the keyvalue for that dataitem) into my codebehind so I can then pass it to another page to bring up a record for editing based on that key value.
I'm having trouble getting the attached error:
My markup is as follows: You can see that the lnkPLMN is the hyperlink. Everything is coming out on the grid just fine, I just can't seem to pass the value.
<telerik:RadGrid ID="RadGrid1" DataSourceID="SqlDataSource1" ShowStatusBar="true"
runat="server" AllowPaging="True" AllowSorting="True" AllowFilteringByColumn="True"
AutoGenerateColumns="false" ClientSettings-Resizing-AllowColumnResize="true"
DataKeyNames="CarrierNetID" OnItemDataBound="RadGrid_ItemDataBound">
<MasterTableView PageSize="10" Width="100%">
<Columns>
<telerik:GridBoundColumn DataField="CarrierNetID" Visible="false" ItemStyle-HorizontalAlign="Left" HeaderStyle-HorizontalAlign="Left"></telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="Name" HeaderText="Carrier Name" UniqueName="Name" SortExpression="Name" ReadOnly="true" ItemStyle-HorizontalAlign="Left" HeaderStyle-HorizontalAlign="Left"></telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="Region" HeaderText="Region" UniqueName="Region" AllowFiltering="true" SortExpression="Region" ReadOnly="true" ItemStyle-HorizontalAlign="Left" HeaderStyle-HorizontalAlign="Left"></telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="Country" HeaderText="Country" UniqueName="Country" SortExpression="Country" ReadOnly="true" ItemStyle-HorizontalAlign="Left" HeaderStyle-HorizontalAlign="Left"></telerik:GridBoundColumn>
<telerik:GridTemplateColumn HeaderText="PLMN" UniqueName="PLMN">
<ItemTemplate>
<asp:HyperLink ID="lnkPLMN" runat="server" Target="_blank" ForeColor="Blue">
</asp:HyperLink>
</ItemTemplate>
</telerik:GridTemplateColumn>
<telerik:GridBoundColumn DataField="TechnologyTypeCode" HeaderText="Technology" UniqueName="TechnologyTypeCode" SortExpression="TechnologyTypeCode" ReadOnly="true" ItemStyle-HorizontalAlign="Left" HeaderStyle-HorizontalAlign="Left"></telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="SMSMORate" HeaderText="SSMSO Rate" UniqueName="SMSMORate" AllowFiltering="false" SortExpression="SMSMORate" ReadOnly="true" ItemStyle-HorizontalAlign="Right" HeaderStyle-HorizontalAlign="Right" DataFormatString="{0:G}"></telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="SMSMTRate" HeaderText="SMSMT Rate" UniqueName="SMSMTRate" AllowFiltering="false" SortExpression="SMSMTRate" ReadOnly="true" ItemStyle-HorizontalAlign="Right" HeaderStyle-HorizontalAlign="Right" DataFormatString="{0:G}"></telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="DataRate" HeaderText="Data Rate" UniqueName="DataRate" AllowFiltering="false" SortExpression="DataRate" ReadOnly="true" ItemStyle-HorizontalAlign="Right" HeaderStyle-HorizontalAlign="Right" DataFormatString="{0:G}"></telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="MOCRate" HeaderText="MOC Rate" UniqueName="MOCRate" AllowFiltering="false" SortExpression="MOCRate" ReadOnly="true" ItemStyle-HorizontalAlign="Right" HeaderStyle-HorizontalAlign="Right" DataFormatString="{0:G}"></telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="MTCRate" HeaderText="MTC Rate" UniqueName="MTCRate" AllowFiltering="false" SortExpression="MTCRate" ReadOnly="true" ItemStyle-HorizontalAlign="Right" HeaderStyle-HorizontalAlign="Right" DataFormatString="{0:G}"></telerik:GridBoundColumn>
<telerik:GridCheckBoxColumn DataField="FlatRate" HeaderText="Flat Rate" UniqueName="FlatRate" SortExpression="FlatRate" ReadOnly="true" ItemStyle-HorizontalAlign="Center" HeaderStyle-HorizontalAlign="Center"></telerik:GridCheckBoxColumn>
<telerik:GridCheckBoxColumn DataField="Discount" HeaderText="Discount" UniqueName="Discount" SortExpression="Discount" ReadOnly="true" ItemStyle-HorizontalAlign="Center" HeaderStyle-HorizontalAlign="Center"></telerik:GridCheckBoxColumn>
<telerik:GridCheckBoxColumn DataField="ActiveFlag" HeaderText="Active" UniqueName="ActiveFlag" SortExpression="ActiveFlag" ReadOnly="true" ItemStyle-HorizontalAlign="Center" HeaderStyle-HorizontalAlign="Center"></telerik:GridCheckBoxColumn>
</Columns>
</MasterTableView>
<ClientSettings EnableRowHoverStyle="true">
</ClientSettings>
<PagerStyle Mode="NumericPages"></PagerStyle>
</telerik:RadGrid>
Here is my codebehind which gets the attached error on the following line:
HyperLink link = (HyperLink)item["PLMN"].Controls[0];
protected void RadGrid_ItemDataBound(object sender, GridItemEventArgs e)
{
if (e.Item is GridDataItem)
{
GridDataItem item = (GridDataItem)e.Item;
HyperLink link = (HyperLink)item["PLMN"].Controls[0];
string value = item.GetDataKeyValue("CarrierNetID").ToString();
link.NavigateUrl = "~/CarrierLaunchStatusForm.aspx?addRecord=0&ID=" + value;
}
}
Can someone please help?
After placing the hyperlink in the markup (instead of the code behind), I'm getting the following compilation error:
Error 2 The GridHyperLinkColumn control with a two-way databinding to field PLMN must have an ID. C:\Projects\NPP\NPP\NPP\NPP\CarrierLaunchStatus.ascx 53
Error 3 Literal content ('</telerik:GridHyperLinkColumn>') is not allowed within a 'Telerik.Web.UI.GridColumnCollection'. C:\Projects\NPP\NPP\NPP\NPP\CarrierLaunchStatus.ascx 56
The Hyperlink column looks as follows:
<telerik:GridHyperLinkColumn UniqueName="PLMN" DataTextFormatString='<%# Bind("PLMN") %>'
DataTextField="PLMN" DataNavigateUrlFields="CarrierNetID" DataNavigateUrlFormatString="~/CarrierLaunchStatusForm.aspx?addRecord=0&ID={0}"
Target="_blank">
</telerik:GridHyperLinkColumn>
What am I missing here?
Unless you really need to modify data on the ItemDataBound event, You can just use the GridHyperLinkColumn:
<telerik:GridHyperLinkColumn DataNavigateUrlFields="CarrierNetID"
DataNavigateUrlFormatString="~/CarrierLaunchStatusForm.aspx?addRecord=0&ID={0}"
Target="_blank" Text="Your Link Text"></telerik:GridHyperLinkColumn>
Hi all I am using RadGrid in my application, as I want my RadGrid not to refresh I had my RadGrid in an Update Panel as follows
<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Always">
<Triggers>
<asp:AsyncPostBackTrigger ControlID="RadGrid1" EventName="ItemCommand" />
<%--<asp:PostBackTrigger ControlID="RadGrid1" />--%>
</Triggers>
<ContentTemplate>
<telerik:RadGrid ID="RadGrid1" runat="server" AutoGenerateColumns="false" OnItemCommand="RadGrid1_ItemCommand"
OnNeedDataSource="RadGrid1_NeedDataSource">
<MasterTableView Width="950" AutoGenerateColumns="false" DataKeyNames="EmpID" GridLines="None"
TableLayout="Auto">
<Columns>
<telerik:GridBoundColumn DataField="EmpID" HeaderText="Emp ID" ReadOnly="true" HeaderStyle-HorizontalAlign="Left"
ItemStyle-HorizontalAlign="Left" UniqueName="EmpID" FilterControlWidth="30px"
AutoPostBackOnFilter="true" CurrentFilterFunction="Contains" />
<telerik:GridButtonColumn DataTextField="ButtonName" ItemStyle-ForeColor="Blue" CommandName="Generate"
ConfirmTextFields="ButtonName" ConfirmTextFormatString="Would you like to {0} ACH file ?"
ConfirmDialogType="RadWindow" Reorderable="false" UniqueName="ButtonName" ConfirmTitle="ACH File">
</telerik:GridButtonColumn>
<telerik:GridBoundColumn DataField="EmployeeName" HeaderText="Employee Name" ReadOnly="true"
HeaderStyle-HorizontalAlign="Left" ItemStyle-HorizontalAlign="Left" UniqueName="EmployeeName"
FilterControlWidth="60px" AutoPostBackOnFilter="true" CurrentFilterFunction="Contains" />
</Columns>
</MasterTableView>
</telerik:RadGrid>
</ContentTemplate>
</asp:UpdatePanel>
When I click on download button I am unable to download the file this is my code in Itemcommand
protected void RadGrid1_ItemCommand(object sender, Telerik.Web.UI.GridCommandEventArgs e)
{
if (e.CommandName == "Generate")
{
Response.ContentType = "text/plain";
Response.AppendHeader("Content-Disposition", "attachment;filename= errorLog.txt");
Response.AddHeader("content-length", "0");
Response.Flush();
Response.End();
}
}
Can some one help me how can I work out this using AsyncPostBackTrigger
You cannot call Response with AsyncPostBack. It is Ajax Framework limitation.
Updated 1/28/2013
Since you are using telerik, I prefer using RadAjaxManager. Basically, when Generate button is clicked, it uses regular post back instead of ajax. In my example, sorting still uses ajax.
<telerik:RadGrid ID="RadGrid1" AutoGenerateColumns="false" AllowSorting="True" runat="server"
OnNeedDataSource="RadGrid1_NeedDataSource" OnItemCommand="RadGrid1_ItemCommand">
<MasterTableView DataKeyNames="EmpID">
<Columns>
<telerik:GridTemplateColumn>
<ItemTemplate>
<asp:Button runat="server" CommandName="Generate" ID="GenerateButton"
Text="Generate" OnClientClick="Generate(this, event); return false;" />
</ItemTemplate>
</telerik:GridTemplateColumn>
<telerik:GridBoundColumn DataField="EmpID" HeaderText="Emp ID" UniqueName="EmpID" SortExpression="EmpID" />
<telerik:GridBoundColumn DataField="EmployeeName" HeaderText="Employee Name" UniqueName="EmployeeName" />
</Columns>
</MasterTableView>
</telerik:RadGrid>
<%-- RadAjaxManager --%>
<telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">
<AjaxSettings>
<telerik:AjaxSetting AjaxControlID="RadGrid1">
<UpdatedControls>
<telerik:AjaxUpdatedControl ControlID="RadGrid1" LoadingPanelID="RadAjaxLoadingPanel1" />
</UpdatedControls>
</telerik:AjaxSetting>
</AjaxSettings>
</telerik:RadAjaxManager>
<%-- RadAjaxLoadingPanel --%>
<telerik:RadAjaxLoadingPanel ID="RadAjaxLoadingPanel1" runat="server" Skin="Default">
</telerik:RadAjaxLoadingPanel>
<telerik:RadCodeBlock ID="RadCodeBlock1" runat="server">
<script type="text/javascript">
function Generate(sender, e) {
$find("<%= RadAjaxManager1.ClientID %>").__doPostBack(sender.name, "");
}
</script>
</telerik:RadCodeBlock>
public class Employee
{
public int EmpID { get; set; }
public string EmployeeName { get; set; }
}
protected void RadGrid1_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
{
RadGrid1.DataSource = new List<Employee>
{
new Employee {EmpID = 1, EmployeeName = "John"},
new Employee {EmpID = 2, EmployeeName = "Marry"},
new Employee {EmpID = 3, EmployeeName = "Eric"}
};
}
protected void RadGrid1_ItemCommand(object sender, GridCommandEventArgs e)
{
if (e.CommandName == "Generate")
{
Response.ContentType = "text/plain";
Response.AppendHeader("Content-Disposition", "attachment;filename= errorLog.txt");
Response.AddHeader("content-length", "0");
Response.Flush();
Response.End();
}
}