How to create ItemTemplate by code in Telerik - telerik-grid

I created the following piece of code using Telerik:
<telerik:RadGrid ID="RadGrid1" runat="server" DataSourceID="LinqDataSource1" AllowPaging="True" AutoGenerateColumns="False" Width="50%" AllowSorting="True">
<MasterTableView DataKeyNames="OrderID" DataSourceID="LinqDataSource1" PageSize="5">
<Columns>
<telerik:GridTemplateColumn DataField="Order" HeaderText="Order" UniqueName="Order">
<ItemTemplate>
<asp:Label runat="server" Text='<%#Eval("Order") %>'/>
</ItemTemplate>
</telerik:GridTemplateColumn>
</Columns>
</MasterTableView>
</telerik:RadGrid>
How I can declare the code that is within the "ItemTemplate" (the "Label") in the Page.Init?

I think you would need to use the grids ItemDataBound event rather than Page.Init, here is a code example from the telerik site showing how you might implement your logic http://www.telerik.com/help/aspnet-ajax/grid-conditional-image-display-in-grid-column.html

Creating Template Columns Programmatically
When creating template columns programmatically, the grid must be generated completely in the code-behind using the Page_Init event. Then, you must create the templates dynamically in the code-behind and assign them to the ItemTemplate and EditItemTemplate properties of the column. To create a template dynamically, you must define a custom class that implements the ITemplate interface. Then you can assign an instance of this class to the ItemTemplate or EditTemplateTemplate property of the GridTemplateColumn object.
From here
You might have problems with the above approach. If it doesn't work, try creating the whole column programmatically. This above link shows how to implement it.

Related

Display Inventory summary line found in SOOrderEntry on other pages

To be more specific, I am referring to the line contained within the SOLine grid:
Is there an easy way to implement the same function they are using to generate this, or would it just be easier if I wrote my own? I did find how to attach it to a grid:
<px:PXGrid ID="grid" runat="server" DataSourceID="ds" Width="100%"
TabIndex="100" SkinID="DetailsInTab" StatusField="Availability"
SyncPosition="True" Height="473px">
Specifically the StatusField attribute of the PXGrid. I also found that the code to perform the action is located in ~/App_Data/CodeRepository/PX.Objects/SO/Descriptor/Attribute.cs. I believe I can imitate the logic that this performs, but I'd like to use it instead of recreating it if that is possible.
I think something like this should give you what you need...
How to display product availability in Opportunity Products Grid footer?
The same logic can be used for any page with a grid.

How to make ext.net RadioGroup a required field?

We are using ext.net. I know how to make a textbox a required field, but am having trouble to force our user to make a selection on the radio group or a check box group. I know someone just assign a default value to one of the radio button, but our customer wants to leave them unchecked in the beginning but forces the web users to make a choice, which is understandable.
It appears IndicatorText and AllowBlank properties are not effective even though they are listed in the IntelliSense.
<ext:RadioGroup ID="rdGrpGender" runat="server"
ItemCls="x-check-group-base" FieldLabel="Gender"
ColumnsWidths="60,60"
IndicatorText="*" IndicatorCls="cssIndicator" AllowBlank="false">
<Items>
<ext:Radio ID="rdoMale" runat="server" BoxLabel="M" />
<ext:Radio ID="rdoFemale" runat="server" BoxLabel="F" />
</Items>
</ext:RadioGroup>
Can any expert help me out? Thanks a lot.
you can validate it like this
<ext:Button ID="Button1" runat="server" Text="Validate"><Listeners><Click Handler="#{rdGrpGender}.validate();" /></Listeners></ext:Button>

How to get document datasource in another Custom Control?

I have an xPage with this content:
<div class="lotusFrame">
<xc:layoutCommonBanner />
<xp:callback facetName="facetTitleBar" id="callbackTitleBar" />
<xc:layoutDiscrepancyPlaceBar />
<div class="lotusMain">
<div class="lotusColLeft">
<xp:callback facetName="facetColLeft" id="callbackColLeft" />
</div>
<div class="lotusColRight">
<xp:callback facetName="facetColRight" id="callbackColRight" />
</div>
<div class="lotusContent">
<xp:callback facetName="facetContent" id="callbackContent" />
</div>
</div>
<xc:layoutCommonFooter />
<xc:layoutCommonLegal />
</div>
As you can see, there are several custom controls in it composing layout. In the facetContent, there is a document with document datasource. It's the only document in the page. I need to get this document somehow in the layoutDiscrepancyPlaceBar custom control.
I found some old articles on the web with undocumented feature called currentDocument. It should be on every page with document datasource. But it doesn's work. I have Domino 8.5.2 and currentDocument seems to be no longer supported.
Can you help me out? How can I get document datasource from one custom control in another custom control. Is it even possible?
Thanks in advance, Jiří
EDIT: OK, it is still supported, but it only works in custom control, that is included inside the one with document datasource. In the case scenario above it doesn't work.
Your best option is to hand over the binding name in a custom property. (lets call it bindto. Then you bind your field to
"${#{"+compositeData.bindto+"}}"
See details here (inside the prezi)
P.S. currentDocument is documented somewhere.
You can also pass a handle on the data source directly to the custom control, as well as the name of the item to bind to on the data source. Because EL supports array syntax as well as dot syntax, this allows you to define expressions like this:
#{compositeData.dsn[compositeData.fieldName]}
(where "dsn" is the property being passed the handle on the data source, and "fieldName" is the property being passed the name of the item to bind to on that data source.)
More details on this approach can be found here.

SharePoint BCS creating a hyperlink column

I am using the .NET connector to connect to an SQL database. One of this value is a URL. Now I need to display this as a URL.
Any ideas on how to solve this?
In Sharepoint Designer you can edit the read list and go to the field, so for example you have a field called URL, display it as a label so it would render like
<asp:Label runat="server" id="ff1{$ID}" text="{$thisNode/#URL}" />
Then all you need to do is add an "A href" tag to it so it renders as a url like such
<asp:Label runat="server" id="ff1{$ID}" text="{$thisNode/#URL}" />

Exporting Gridview to Excel in web app

Hopefully you guys can help me out. I tried a lot of different things and cant get this working.
I have a gridview as below in a update panel:
<asp:UpdatePanel ID="udpReport" runat="server" UpdateMode="Conditional" ChildrenAsTriggers="true">
<ContentTemplate>
<asp:GridView runat="server" ID="preferenceReportGrd" AutoGenerateColumns="false"
AutoGenerateSelectButton="false" CaptionAlign="Top" EnableSortingAndPagingCallbacks="false" HorizontalAlign="left" CssSelectorClass="gvwPrefReport">
<Columns>
<asp:BoundField ReadOnly="true" DataField="ClientName" HeaderText="Company Name" />
<asp:BoundField ReadOnly="true" DataField="typeDescription" HeaderText="Preference" />
<asp:BoundField ReadOnly="true" DataField="defaultValue" HeaderText="Default Preference" />
<asp:BoundField ReadOnly="true" DataField="previousPreferenceValue" HeaderText="Previous Preference" />
<asp:BoundField ReadOnly="true" DataField="selectedValue" HeaderText="New Preference" />
<asp:BoundField ReadOnly="true" DataField="lastUpdated" HeaderText="Date Last Edited" />
</Columns>
</asp:GridView>
<div>
<user:MsgLine runat="server" ID="MsgLine1" />
</div>
</ContentTemplate>
</asp:UpdatePanel>
I am trying to export this gridview out to excel. There is a button which the user clicks on it calls the on_click method for that button and in this on_click i have the following:
string attachment = "attachment; filename=Employee.xls";
Response.AddHeader("content-disposition", attachment);
Response.ContentType = "application/excel";
StringWriter stw = new StringWriter();
HtmlTextWriter htextw = new HtmlTextWriter(stw);
preferenceReportGrd.RenderControl(htextw);
Response.Write(stw.ToString());
Response.End();
I get nothing from this tried debugging it seems that when i mouse over stw.tostring() all the values for the gridview are there but nothing gets written out.
Yes. within the update panel tag excel export is not working. I face the same problem.
To solve this use the following code in end of the update panel tag
</ContentTemplate>
<Triggers>
<asp:PostBackTrigger ControlID="BtnExport" />
</Triggers>
</asp:UpdatePanel>
it works even within the update panel also
If the GridView and/or the button is within in update panel with an async postback, I do not believe you can change the response headers or information. Try running it again with a full postback on the button trigger and see what happens. Your code did not look incorrect, but I've not tried it...
Take a look at this samples...
1. c-sharpcorner
2. Matt Berseth
3. Code Project
Check your content types and for a PostBackTrigger on the exporting button.
For Excel 2003
Response.ContentType = "application/vnd.ms-excel
For Excel 2007
Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
You can check out this blog post for the source of my content types.
EDIT: From your comments:
You need to set a PostBackTrigger on the panel that contains the button doing the export, not the panel that contains the GridView.
EDIT EDIT: Your file-is-not-what-it-says-it-is error is due to a feature called Extension Hardening, present in Excel 2007. Check this StackOverflow question for more info; I linked to a blog post describing the reasoning for this error and a possible workaround.
The way I was able to work around this in a simple page that I was working on was to have a hidden gridview outside of the updatepanel and set it equal to the gridview in the update panel so that they are the same (except for the new one being hidden). Then export this hidden grid to Excel the same way that you were doing it before.
One issue with doing it this way is that the export hyperlink needs to be outside of the update panel as well which means that you might not be able to put the export hyperlink where you want it.
Granted this is probably not the best way to do it, it got me around this issue at the time. Hope it helps.

Resources