<telerik:RadGrid runat="server" ID="rdReport" AutoGenerateColumns="false" AllowPaging="true" Skin="Metro" OnItemCommand="ItemCommand" OnItemDataBound="rdReport_ItemDataBound" OnPreRender="rdReport_PreRender" DataSourceID="FountainSource" AllowAutomaticUpdates="true" AllowAutomaticDeletes="true">
<MasterTableView DataKeyNames="ID" CommandItemDisplay="None">
<Columns>
<telerik:GridEditCommandColumn ButtonType="ImageButton" />
<telerik:GridBoundColumn DataField="LocName" HeaderText="Location" ReadOnly="true" />
<
<telerik:GridBoundColumn DataField="Field1Value" HeaderText="Custom Field1" />
<telerik:GridBoundColumn DataField="Field2Value" HeaderText="Custom Field2" />
<telerik:GridBoundColumn DataField="Field3Value" HeaderText="Custom Field3" />
<telerik:GridButtonColumn ConfirmText="Delete?" ConfirmDialogType="RadWindow"
ConfirmTitle="Delete" ButtonType="ImageButton" CommandName="Delete" />
</Columns>
<EditFormSettings>
<EditColumn ButtonType="ImageButton" />
</EditFormSettings>
</MasterTableView>
<PagerStyle Mode="NextPrevAndNumeric" />
</telerik:RadGrid>
On Edit, I like to make a field invisible.
I am using the following code which works but want to check to see if it is best practice:
protected void rdReport_ItemDataBound(object sender, GridItemEventArgs e)
{
// Edit Mode
if ((e.Item is GridEditFormItem) && (e.Item.IsInEditMode))
{
GridEditFormItem fndColumn = (GridEditFormItem)e.Item;
fnColumn["Field1Value"].Parent.Visible = false;
}
}
The solution which was provided by you is perfect but it would be nice if you will also add UniqueName property in each column. If we will not assign the UniqueName than it is consider DataField value as UniqueName.
ASPX
<telerik:GridButtonColumn DataField="Field1Value" HeaderText="Custom Field1" UniqueName="Field1Value" />
ASPX.CS
protected void rdReport_ItemDataBound(object sender, GridItemEventArgs e)
{
// Edit Mode
if ((e.Item is GridEditFormItem) && (e.Item.IsInEditMode))
{
GridEditFormItem fndColumn = (GridEditFormItem)e.Item;
fnColumn["Field1Value"].Parent.Visible = false; // "Field1Value" is column uniquename
}
}
Let me know if you required more information.
This is just a suggested alternative. I've worked with telerik a few times, and it is a pain to say the least. What you could do is also add a tertiary condition to the parent container. If in edit mode, then show a class, such as 'edit', or 'current'. If not in edit mode, don't show the class. Then, in your CSS you can select for whatever element you want to hide.
<div>
<input type="text" id="whateverisgenerated" class="uniqueclass" />
</div>
Then, when in edit mode, you will have
<div class="edit">
<input type="text" id="whateverisgenerated" class="uniqueclass" />
</div>
With your CSS:
div.edit input.uniqueclass { display: none; }
As for your telerik control (I just grabbed something from your code), you can do the following to add your class:
<telerik:GridButtonColumn ConfirmText="Delete?" ConfirmDialogType="RadWindow" ConfirmTitle="Delete" ButtonType="ImageButton" CommandName="Delete" CssClass="uniqueclass" />
I added CssClass="uniqueclass" in the control above.
What I provided is just an example. I hope you find a use for it. Thanks
Related
I have an ASP.NET WebForms Application and am encountering one of the oddest problems in my nine months of coding in ASP.NET.
I added two new pages that both use Telerik Radgrids. Both Radgrids are identical, so I will focus on one of them in the hopes that solving one of the problems will solve the other.
Html
<telerik:RadGrid ID="_radgrid" runat="server" Width="100%" Visible="true"
AutoGenerateColumns="false" OnSortCommand="_btnSearch_Click" PagerStyle-AlwaysVisible="true"
Skin="Office2007" AllowFilteringByColumn="true" AllowSorting="true" AllowPaging="true"
PageSize="50" OnNeedDataSource="_radgrid_NeedDataSource" OnItemDataBound="_radgrid_OnItemDataBound"
AllowMultiRowSelection="true">
<MasterTableView AllowFilteringByColumn="true" CommandItemDisplay="TopAndBottom">
<CommandItemTemplate>
<asp:Button ID="_btnResolve" runat="server" Text="Resolve" OnClick="_btnResolve_Click"
Visible="False" ClientIDMode="Inherit" />
</CommandItemTemplate>
<NoRecordsTemplate>
No records to display.</NoRecordsTemplate>
<Columns>
<telerik:GridBoundColumn DataField="Id" Visible="false" />
<telerik:GridBoundColumn DataField="Resolved" Visible="false" />
<telerik:GridClientSelectColumn UniqueName="CheckboxSelectColumn" FooterText="CheckBoxSelect footer"
Visible="false" />
<telerik:GridHyperLinkColumn DataNavigateUrlFields="Id" AllowFiltering="false"
DataNavigateUrlFormatString="~/UpdatePage.aspx?Id={0}"
Text="Update" UniqueName="UpdateHyperLink" />
<telerik:GridBoundColumn DataField="TradingPartnerName" HeaderText="Trading Partner Name" />
<telerik:GridBoundColumn DataField="DocumentType" HeaderText="Transaction Set" />
<telerik:GridBoundColumn DataField="DocumentID" HeaderText="Document ID" />
<telerik:GridBoundColumn DataField="Description" HeaderText="Description" />
</Columns>
</MasterTableView>
<ClientSettings>
<Selecting AllowRowSelect="true" />
<ClientEvents OnRowDblClick="RowDblClick" />
</ClientSettings>
</telerik:RadGrid>
Code Behind
protected void _radgrid_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
{
Fill_radgrid();
}
private void Fill_radgrid(bool dataBind = false)
{
//Data Manager is a class that I built that makes all of the Database calls. It returns a DataSet
_grdNegativeAck.DataSource = DataManager.GetRecords(_txtBoxId.Text, txtBoxDocumentType.Text, _chkBoxIncludeResolved.Checked, int.Parse(_ddlTradingPartner.SelectedValue));
if (dataBind)
_grdNegativeAck.DataBind();
}
protected void _radgrid_OnItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e)
{
if (e.Item is GridCommandItem)
{
//If the current user is authorized to resolve, show the Resolve button on the grid
if (currentUser.IsAuthorized))
{
GridCommandItem cmditem = (GridCommandItem)e.Item;
Button _btnResolve = (Button)cmditem.FindControl("_btnResolve");
_btnResolve.Visible = true;
_grdNegativeAck.MasterTableView.GetColumn("CheckboxSelectColumn").Visible = true;
}
}
else if (e.Item is GridDataItem)
{
//If the record is already resolved, do not show the checkbox on the side and color the record green
GridDataItem GDItem = e.Item as GridDataItem;
if (GDItem["Resolved"].Text.ToUpper() == "TRUE")
{
((e.Item as GridDataItem)["CheckboxSelectColumn"].Controls[0] as CheckBox).Visible = false;
(e.Item as GridDataItem).BackColor = System.Drawing.Color.Green;
}
}
}
Here's where things get interesting. On my localhost, when using the same database, I get 0 records returned. I checked the DataSet that I'm binding to, and there is literally 0 rows. When I query the database, I get 185 records no problem. I double-checked the parameters I pass to the query, and they're the same. When I put this same code on the Test site, the page will get 184 records... when it should be matching exactly and get 185 records.
The other page doesn't get any records on either my localhost or my test site.
I'm really at my wit's end here. Anyone encounter a similar situation or have somewhere they can point me?
_grdNegativeAck.DataSource = DataManager.GetRecords(_txtBoxId.Text, txtBoxDocumentType.Text _chkBoxIncludeResolved.Checked, int.Parse(_ddlTradingPartner.SelectedValue));
In the above line, you are missing a comma(,) after txtBoxDocumentType.Text.
Hope this will resolve your problem.
I've scoured the web looking at the various examples and have tried every single one of them. I get the same error no matter what. I am trying to add the headerrow to the GridView control in code. I have tried adding the below code in every possible event from gridview prerender to all of the events of the page. Same deal. Always get the error: The table must contain row sections in order of header, body, then footer.
I have stripped down the page to the bare essentials - removing the master page and all CSS.
Here is the aspx and grid view code:
<%# Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="Shipping.Admin.Default" Title="Apps - Shipping" %>
<html>
<head><title></title></head>
<body>
<form runat="server" id="form1">
<br />
<h1>Admin Page</h1>
<br />
<asp:GridView ID="gvShipments" runat="server" AllowSorting="True"
AutoGenerateColumns="False" onsorting="gvShipments_Sorting" Width="100%"
AllowPaging="True" onpageindexchanging="gvShipments_PageIndexChanging"
PageSize="50">
<PagerSettings Position="TopAndBottom" />
<Columns>
<asp:BoundField DataField="RequestDate" HeaderText="Request Date" SortExpression="dtRequestDate" />
<asp:BoundField DataField="Requestor" HeaderText="Requestor" SortExpression="Requestor" />
<asp:BoundField DataField="CompanyName" HeaderText="Company" SortExpression="CompanyName" />
<asp:BoundField DataField="ShipmentDescription" HeaderText="Description" SortExpression="ShipmentDescription" />
<asp:BoundField DataField="City" HeaderText="City" SortExpression="City" />
<asp:BoundField DataField="State" HeaderText="State" SortExpression="State" />
<asp:BoundField DataField="ShipmentType" HeaderText="Shipment Type" SortExpression="ShipmentType" />
<asp:BoundField DataField="ServiceLevel" HeaderText="Service Level" SortExpression="ServiceLevel" />
<asp:BoundField DataField="Status" HeaderText="Status" SortExpression="Status" />
<asp:HyperLinkField DataNavigateUrlFields="ShipmentId" DataNavigateUrlFormatString="Shipment.aspx?CatId=Admin&sID={0}" Text=" edit" />
</Columns>
</asp:GridView>
<br />
</form>
</body>
</html>
Here is a snipped of the code-behind. This method is called in the Page_Load method:
private void LoadGridView()
{
DataSet ds = new DataSet();
ds = GetDataset();
DataTable dtRequests = ds.Tables["Admin"];
DataView dv = new DataView(dtRequests);
if (ViewState["sortexpression"] != null)
{
dv.Sort = ViewState["sortexpression"].ToString() + " " + ViewState["sortdirection"].ToString();
}
else
{
dv.Sort = "dtRequestDate DESC";
}
gvShipments.DataSource = dv;
gvShipments.DataBind();
**if (gvShipments.Rows.Count > 0)
{
this.gvShipments.UseAccessibleHeader = true;
this.gvShipments.HeaderRow.TableSection = TableRowSection.TableHeader;
}**
ds.Dispose();
}
I have tried adding the code inside bolded the IF statement everywhere. I am stumped. Please help!
Thanks
Try this add Page_PreRender event and post your code inside it, then your code look like as below
protected void Page_PreRender(object sender, EventArgs e)
{
if (gvShipments.Rows.Count > 0)
{
gvShipments.UseAccessibleHeader = true;
gvShipments.HeaderRow.TableSection = TableRowSection.TableHeader;
}
}
PageLifeCycle
I have a grid view with below markup and below datasourse (linq query-stored procedure), I have added delete and update command field, but I do not know what code I have to add until deleting and updating for this grid view works.
<asp:GridView ID="GridViewDocuments_Search" runat="server" AutoGenerateColumns=False Visible="False" onrowcommand="GridViewDocuments_Search_RowCommand"
DataKeyNames="DocID" PageSize="100" >
<Columns>
<asp:TemplateField HeaderText = "Details">
<ItemTemplate>
<asp:Button ID ="btn_Show" Text="Details" runat= "server" CommandName= "Details" CommandArgument='<%#
Container.DataItemIndex%>' />
</ItemTemplate>
</asp:TemplateField>
<asp:HyperLinkField DataNavigateUrlFields="Docid,Transid"
DataNavigateUrlFormatString="~/DocResult.aspx?Docid={0}&TransID={1}"
DataTextField="DocumentNo" HeaderText="Doc" />
<asp:BoundField DataField="title" HeaderText="Title" SortExpression="title" />
<asp:BoundField DataField="transmittal" HeaderText="transmittal" SortExpression="transmittal" />
<asp:BoundField DataField="Docid" HeaderText="Docid" Visible="false" />
<asp:CommandField ShowEditButton="True" />
<asp:CommandField ShowDeleteButton="True" />
</Columns>
</asp:GridView>
protected void btnSearch_Click(object sender, EventArgs e)
{
_DataContext = new EDMSDataContext();
var query = _DataContext.spQuickSearch(txtSearchKeywords.Text);
GridViewDocuments.Visible = false;
GridViewDocuments_Search.Visible = true;
GridViewDocuments_Search.DataSource = query;
GridViewDocuments_Search.DataBind();
}
The stored procedure spQuickSearch is like below:
ALTER proc [dbo].[spQuickSearch]
#Searchtext varchar(50)=null
AS
select DocId,TransId,DocumentNo,Title,TRANSMITTAL
from DocumentSum2
where DocumentNo like '%'+#SearchText + '%'
or Title like '%'+#SearchText + '%'
or TRANSMITTAL like '%'+#SearchText + '%'
You can handle commands like this:
protected void GridViewDocuments_Search_RowCommand(object sender, GridViewCommandEventArgs e)
{
string cmdArg = e.CommandArgument.ToString();
switch (e.CommandName)
{
case "Details":
//TODO: handle your Details command...
break;
case "Delete":
//TODO: handle your Delete command...
break;
}
}
You can add as many commands as you want (CommandName property for control). For example you can add another button and set Delete CommandName like this:
<asp:Button ID ="btn_Delete" Text="Delete" runat= "server" CommandName= "Delete" CommandArgument='<%#
Container.DataItemIndex%>' />
After command is completed you can call DataBind to refresh grid:
GridViewDocuments_Search.DataBind();
check this example
http://www.vkinfotek.com/gridview/gridview-commandfield.html
for detail
http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.commandfield.showeditbutton.aspx
I have an ASPxGridView, currently 11.1.7.0, which I populate with an ObjectDatasource. Everything works as expected until I use a custom editform. In another control i solved this by using the OnRowInserting attribute in the aspxgridview control, but I dont like this since it's extra work compared to using the objectdatasource.
The code looks something like this.
<dx:ASPxGridView ID="ASPxGridView1" runat="server"
ClientIDMode="AutoID"
AutoGenerateColumns="False"
KeyFieldName="UserId"
DataSourceID="ObjectDataSource1"
ClientInstanceName="grid"
onhtmleditformcreated="AsPxGridView1HtmlEditFormCreated">
<SettingsEditing PopupEditFormWidth="600" PopupEditFormModal="true" Mode="EditForm" />
<Templates>
<TitlePanel>
<dx:ASPxButton ID="New" runat="server" Text="Ny användare" ClientInstanceName="New" AutoPostBack="false">
<ClientSideEvents Click="function (s, e) { grid.AddNewRow(); }" />
</dx:ASPxButton>
</TitlePanel>
<EditForm>
First Name: <dx:ASPxTextBox ID="FirstName" runat="server" />
<dx:ASPxGridViewTemplateReplacement ID="UpdateButton" ReplacementType="EditFormUpdateButton" runat="server" />
<dx:ASPxGridViewTemplateReplacement ID="CancelButton" ReplacementType="EditFormCancelButton" runat="server" />
</EditForm>
</Templates>
<Columns>
<dx:GridViewDataTextColumn FieldName="UserId" VisibleIndex="0" />
<dx:GridViewDataTextColumn FieldName="FirstName" VisibleIndex="2" />
<dx:GridViewDataTextColumn FieldName="LastName" VisibleIndex="3" />
</Columns>
</dx:ASPxGridView>
<asp:ObjectDataSource
ID="ObjectDataSource1"
TypeName="UserData"
SelectMethod="GetItems"
UpdateMethod="ItemUpdate"
InsertMethod="ItemInsert"
DeleteMethod="ItemDelete"
runat="server">
<InsertParameters>
<asp:Parameter Name="FirstName" Type="String"/>
</InsertParameters>
</asp:ObjectDataSource>
And the UserData object
public class UserData
{
public List<TblProUserData> GetItems()
{
var tblProUserData = new TblProUserData();
tblProUserData.Fill();
return tblProUserData.List;
}
public void ItemDelete(int userId)
{ }
public void ItemUpdate()
{ }
public void ItemInsert(string FirstName)
{
// This method gets called, but the FirstName is null.
}
}
The problem is that the ItemInsert gets called, but the FirstName attribute is always null.
Is this a bug? is there a way around this? Did I miss something?
Thanks.
It is necessary to use the Two-Way data-binding technique to bind template editors with DataItem's fields:
<dx:ASPxTextBox ID="FirstName" runat="server" Text='<%#Bind("FirstName")%>' />
Based off the following question, specifying TypeName="UserData" could be causing the problem.
ObjectDataSource not calling Insert method when it has extra parameters
Try removing that from the asp:ObjectDataSource and see if the ItemInsert method works.
I have a text box and button inside of my ASPXGridview, DetailRow view. So when it's expanded I need to type text and click button and on server side to get value from the textbox.
Here is my code. The problem is somewhere on postback I'm loosing text value. So text box is empty
protected void Button1_Click(object sender, EventArgs e)
{
ASPxGridView grid = EmailGridView;
for (int i = 0; i < grid.VisibleRowCount; i++)
{
var txtDescription = (ASPxMemo)grid.FindDetailRowTemplateControl(i, "txtDescription");
if(txtDescription != null)
{
var text = txtDescription.Text;
}
}
}
<dxwgv:ASPxGridView ID="EmailGridView" KeyFieldName="ThreadId" runat="server" AutoGenerateColumns="False"
OnHtmlRowCreated="EmailGridView_HtmlRowCreated" SettingsDetail-AllowOnlyOneMasterRowExpanded="true"
SettingsBehavior-ConfirmDelete="true" OnHtmlRowPrepared="EmailGridView_HtmlRowPrepared"
OnRowDeleted="EmailGridView_RowDeleted">
<SettingsBehavior ConfirmDelete="True" />
<Columns>
<dxwgv:GridViewDataTextColumn Caption="ID" FieldName="Id" VisibleIndex="0">
</dxwgv:GridViewDataTextColumn>
<dxwgv:GridViewCommandColumn VisibleIndex="5" Caption=" ">
<DeleteButton Visible="True">
</DeleteButton>
</dxwgv:GridViewCommandColumn>
</Columns>
<SettingsDetail ShowDetailRow="true" />
<SettingsBehavior ConfirmDelete="True" />
<SettingsDetail AllowOnlyOneMasterRowExpanded="True" ShowDetailRow="True" />
<Templates>
<DetailRow>
<dxwgv:ASPxGridView ID="EmailSubGridView" Width="750px" OnBeforePerformDataSelect="EmailSubGridView_BeforePerformDataSelect"
runat="server" AutoGenerateColumns="False"
onhtmlrowcreated="EmailSubGridView_HtmlRowCreated">
<Columns>
<dxwgv:GridViewDataTextColumn Caption="MessFrom" FieldName="MessFrom">
</dxwgv:GridViewDataTextColumn>
<dxwgv:GridViewDataTextColumn Caption="Message" FieldName="Message">
</dxwgv:GridViewDataTextColumn>
<dxwgv:GridViewDataTextColumn Caption="SendDtm" FieldName="SendDtm">
</dxwgv:GridViewDataTextColumn>
</Columns>
<StylesEditors>
<ProgressBar Height="25px">
</ProgressBar>
</StylesEditors>
</dxwgv:ASPxGridView>
<dx:ASPxMemo ID="txtDescription" runat="server" Width="170px" Height="71px"></dx:ASPxMemo>
<asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Reply" />
</DetailRow>
</Templates>
Conny,
The ASPxGridView has callbacks built into it so I recommend using that approach as it's easier and it gives you a better user experience. The find method you're using requires the visiblerowindex.
Take a look a this code central example to see how to get data from the server:
How to bind the detail GridView to data based on the end-user input
If you want these process when you are expanding your ASPxGridview, you should use DetailRowExpandedChanged event.
This event works when you expand or collapse your ASPxGridview.
Mehul's example is very good actually for this situation. After that, if you still have a problem, you can ask your question in Devexpress Support. They are really helpful and quick.