how to bind raddropdown from different sources for different rows inside rad grid? - telerik-grid

How to bind the telerik rad containg raddropdown to bind from differrent sources in different rows.
Eg:raddropdown.dataSource=new list<string>{"apple","bat","cat"} in row 0
raddropdown.dataSource=new list<string>{"Dog","egg"}in row 1
Somebody please help.

Following is my dropdown inside a grid.
<telerik:GridTemplateColumn
HeaderText="Employees"
SortExpression="emp_name"
UniqueName="emp_name">
<ItemTemplate>
<asp:Label runat="server" ID="lblName"
Text='<%# Eval("emp_name") %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<telerik:RadComboBox runat="server" ID="comboEmployees"
DataSourceID="odsEmployees"
DataTextField="emp_name"
DataValueField="emp_id">
</telerik:RadComboBox>
</EditItemTemplate>
<InsertItemTemplate>
<telerik:RadComboBox runat="server" ID="comboEmployees"
DataSourceID="odsEmployees"
DataTextField="emp_name"
DataValueField="emp_id">
</telerik:RadComboBox>
</InsertItemTemplate>
</telerik:GridTemplateColumn>
Define a ObjectDataSource as follows.
<asp:ObjectDataSource runat="server" ID="odsEmployees"
SelectMethod="getListOfEmployees"
TypeName="ABC.DEF">
</asp:ObjectDataSource>
Create a code file as follows.
namespace ABC
{
public class DEF{
public List<tbl_employees> getListOfEmployees(){
List<tbl_employees> employees = db.tbl_employees
.Where(e => e.salary > 10000)
.OrderBy(e => e.emp_name)
.ToList();
}
}
}

Related

Add extra note field to grid line

I have a client that would like to add an extra note field to a grid. If this is not possible, is there a way to have a large text field in a grid that uses a pop up window for editing the large amount of text in that field?
Priority:
1.) Add extra note field to grid, if possible.
2.) Failing #1, is there a way to add a popup window to edit a large standard user text field.
I believe the answer to your number 1 question is no. If the grid already has a note it cannot have another. I had this question come up before.
For #2, you should be able to do a smart panel that displays your field. Use a PXTextEdit and setup a new view for the panel to point to based on your selected/current row.
To add a smart panel (pop up panel) you need a handful of things in place. I prefer using AEF with graph and table extensions. There is documentation in the T200/T300 training material for these topics. In my example I add the note ability to the sales order page. I copied most of the logic from the existing "PO Link" button and panel which is the POSupplyOK PXAction and the currentposupply view (page SO301000).
First you need your new field which we will add to the sales line as an extension table/field:
[PXTable(typeof(SOLine.orderType), typeof(SOLine.orderNbr), typeof(SOLine.lineNbr), IsOptional = true)]
public class SOLineExtension : PXCacheExtension<SOLine>
{
#region XXMyNote
public abstract class xXMyNote : PX.Data.IBqlField
{
}
protected string _XXMyNote;
[PXDBString]
[PXUIField(DisplayName = "My Note")]
public virtual string XXMyNote
{
get
{
return this._XXMyNote;
}
set
{
this._XXMyNote = value;
}
}
#endregion
}
Then we need to create a new graph extension to add the view for the panel and the PXAction for the button to open the panel.
public class SOOrderEntryExtension : PXGraphExtension<SOOrderEntry>
{
public PXSelect<SOLine,
Where<SOLine.orderType, Equal<Current<SOLine.orderType>>,
And<SOLine.orderNbr, Equal<Current<SOLine.orderNbr>>,
And<SOLine.lineNbr, Equal<Current<SOLine.lineNbr>>>>>> MyPanelView;
public PXAction<SOOrder> myNoteAction;
[PXUIField(DisplayName = "Add Note", MapViewRights = PXCacheRights.Select, MapEnableRights = PXCacheRights.Update)]
[PXButton(ImageKey = PX.Web.UI.Sprite.Main.DataEntryF)]
protected virtual IEnumerable MyNoteAction(PXAdapter adapter)
{
if (Base.Transactions.Current != null &&
MyPanelView.AskExt() == WebDialogResult.OK)
{
//extra stuff here if needed when OK is pushed
}
return adapter.Get();
}
}
now you need to "edit" the sales order page. you need to get your changes into a customization project and I usually go edit the page direct in visual studio under site\pages\so in this example. Then come back and paste in my code into the customization project by opening the project and performing the following steps:
Click on screens and the + sign to add a new screen
Enter SO301000 and save
Click on the SO301000 hyperlink to open the layout editor for sales order
Click Actions > Edit ASPX
Paste in your changes (mentioned below)
In the SO301000 page add the following:
[1] Add your DS Callback command within the PXDataSource tag
<px:PXDSCallbackCommand Name="MyNoteAction" Visible="False"
CommitChanges="true" DependOnGrid="grid" />
[2] Add the button to the toolbar above the sales line grid by adding the following to the PXGrid > ActionBar > CustomItems tags of the grid in the Document Details tab. (just search "PO Link" in the page to find this location easier or any of the listed buttons above the grid).
<px:PXToolBarButton Text="Add Note" DependOnGrid="grid">
<AutoCallBack Command="MyNoteAction" Target="ds" />
</px:PXToolBarButton>
[3] Add the panel code which represents what the panel will look like. You can play around with the sizing to fit your needs, just make sure you set your PXTextEdit to use MultiLine using the following example code. Look at the current sales order page to know where it fits into the page syntax:
<px:PXSmartPanel ID="PXSmartPanelNote" runat="server" Caption="My Note Panel Caption"
CaptionVisible="true" DesignView="Hidden" LoadOnDemand="true" Key="MyPanelView" CreateOnDemand="false" AutoCallBack-Enabled="true"
AutoCallBack-Target="formMyNote" AutoCallBack-Command="Refresh" CallBackMode-CommitChanges="True" CallBackMode-PostData="Page"
AcceptButtonID="btnMyNoteOk">
<px:PXFormView ID="formMyNote" runat="server" DataSourceID="ds" Style="z-index: 100" Width="100%" CaptionVisible="False"
DataMember="MyPanelView">
<ContentStyle BackColor="Transparent" BorderStyle="None" />
<Template>
<px:PXLayoutRule ID="PXLayoutRule44" runat="server" StartColumn="True" LabelsWidth="S" ControlSize="XM" />
<px:PXTextEdit ID="cstXXMyNote" runat="server" DataField="XXMyNote" TextMode="MultiLine"/>
</Template>
</px:PXFormView>
<px:PXPanel ID="PXPanel10" runat="server" SkinID="Buttons">
<px:PXButton ID="btnMyNoteOk" runat="server" DialogResult="OK" Text="OK"/>
</px:PXPanel>
</px:PXSmartPanel>
I have not fully tested the above but a quick slap together brought up the panel with no errors. I was using version 6.00.0955 but the same steps should work in all 5.X versions. Hope this helps.

How to use SharePoint Field in application page

I am creating application page. On this application page I want to update some SharePoint fields in my List.
So I have created this in aspx file:
<asp:Content ID="Main" ContentPlaceHolderID="PlaceHolderMain" runat="server">
<SharePoint:TextField ControlMode="Edit" runat="server" FieldName="Size" ID="SizeField"></SharePoint:TextField>
</asp:Content>
In cs Page_Load I have this
protected void Page_Load(object sender, EventArgs e)
{
SPList list = SPContext.Current.Web.Lists["Media Content"];
SizeField.ListId = list.ID;
SizeField.ItemId = 5;
}
But When I load the page I got Error.
But When I add to aspx this (ListId and ItemId directly in aspx)
<asp:Content ID="Main" ContentPlaceHolderID="PlaceHolderMain" runat="server">
<SharePoint:TextField ControlMode="Edit" runat="server" FieldName="Size" ID="SizeField" ListId="7a00ae8c-9e8d-4762-81a2-a21b76a24ea7" ItemId="5"></SharePoint:TextField>
</asp:Content>
And Page load in cs is empty it works without any problem....
But I want to change ItemId and ListId dynamically in cs code....Hmm...Thank you
PS: I try also add initialization to OnInit or in CreateChildControls but without success. Thanks
First, I think you should be checking if the splist object does not return null.
Then you can create your objects and write them to the UI. Maybe using a hybrid solution with controls on both aspx and cs is not working out.

xp:text does not render tagName property correctly within a repeat

I'm trying to generate a grid layout from a repeat control. Inside the repeat control i'm using a xp:text control to control my compute the output. When I use the tagName property with the predefined tags the tags are generated correctly.
When i'm using other tags such as tr or td the tag is not rendered at all. Is this a bug or a feature ?
<xp:repeat id="rptViewCategory"
var="PublicationCategory" indexVar="i" disableTheme="true"
repeatControls="false" disableOutputTag="false">
<xp:this.value><![CDATA[#{javascript:return getCategories(pubNav);}]]></xp:this.value>
<xp:text tagName="tr" id="txtHeader">
<xp:this.value><![CDATA[#{javascript:var category:NotesViewEntry = PublicationCategory;
if(category.isCategory()){
var c:NotesViewColumn = vwPublications.getColumn(1);
var nav:NotesViewNavigator = pubNav;
var firstChild = nav.getChild(category);
var values:java.util.Vector = firstChild.getColumnValues();
return values.get(0);
}
}]]></xp:this.value>
</xp:text>
<datatable></datable>
<tr>
<td colspan="4">
<xp:link>
<xp:this.text><![CDATA[#{javascript:return getComponent("txtHeader").value;}]]></xp:this.text>
</xp:link>
</td>
</tr>
</xp:repeat>
How about set the text to display as html, disable the output tag, and just add the inside it
The tagName options are "div", "span", "h1", "h2", and "h3". The renderer will ignore anything that is not one of the options on the list (including "h4" which would seem to be an over site.) Since "tr" is not a valid option it ignores it
So your only choice is to do this with an HTML pass through computed text field.
/Newbs

Displaying an Image/Icon inside an EXT.NET GridPanel Cell depinding on value

Greeting,
I need to display an image/icon AND a value in an EXT.NET cell (of a gridpanel). The value comes from the datatable. The value can either be a string ‘good’ or ‘bad’ and resides in the column ‘Status’.
For example: good accept.png or bad cancel.png.
Layout:
<ext:GridPanel ID="grid" runat="server">
<Store>
<ext:Store ID="Store1" runat="server">
<Reader>
<ext:ArrayReader>
<Fields>
<ext:RecordField Name="status" Mapping="Status" />
</Fields>
</ext:ArrayReader>
</Reader>
</ext:Store>
</Store>
<ColumnModel ID="ColumnModel1" runat="server">
<Columns>
<ext:Column DataIndex="status" Header="Status" Width="160">
</ext:Column>
</Columns>
</ColumnModel>
</ext:GridPanel>
Now I have seen some exaples but I can’t seem to get the picture, I think it has something to do with this:
<script type="text/javascript">
function imgRenderer(value, meta, record, rowIndex, colIndex, store) {
if(data == ‘good’)
{
return "<img src='accept.png'/>"
}
else (data == "bad")
{
return "<img src='cancel.png'/>"
}
}
</script>
More info:
http://miamicoder.com/2009/displaying-an-image-inside-an-ext-js-gridpanel-cell-part-2/
http://techmix.net/blog/2010/11/25/add-button-to-extjs-gridpanel-cell-using-renderer/
I forgot to return the value.
<ext:Column ColumnID="columnStatus" DataIndex="omschrijving" Header="Status" Width="150">
<Renderer Handler="return imgRenderer(value);" />
</ext:Column>
You have options, although I think there is just one minor syntax error that is causing the problem.
Option 1:
In your existing code, you should change data to value.
Example
// existing
if(data == ‘good’)
// revised
if(value == ‘good’)
Option 2:
Rename your images to same value as the value, although this would still require using the value attribute instead of data. Rename accept.png to good.png, and same renaming with the "bad" image. With this change you shouldn't require the if|else statement.
Example
// existing
if(data == ‘good’)
{
return "<img src='accept.png'/>"
}
else (data == "bad")
{
return "<img src='cancel.png'/>"
}
// revised
return '<img src="' + value + '.png"/>';
Hope this helps.

c# fill something on html page

how can I fill "MyUserName" on
<td width="18%" class="more"><div align="right">¿¿¿¿¿¿ </div></td>
<td width="82%">
<font color="#FFFFFF" face="MS Sans Serif, Tahoma, sans-serif">
<input type=text name="QTitle" size=51 maxlength=100 class=violet>
</font>
</td>
i try in c# but it not work please help
private void webBrowser2_DocumentCompleted(object sender,
WebBrowserDocumentCompletedEventArgs e)
{
}
private void LoadProfileInformation()
{
DataSet dsNew = new DataSet();
//Some code to fetch information if you store it in a DB
//else you can put in static info if you may want.
//so you will nto need the dataset.
QTitle.Text = "MyUserName";
}
You can store it in the class then access it with code behinds like <%= myVar %> in your front end.
if you want to modify the values of divs on the front end then you need to use asp tags like
<asp:label runat="server" name="Qtitle"> </asp:label>
First of all you really need to think about moving to newer versions of XHTML/HTML! (I suggest you that because of your markup code).
In the other hand, in order to get your "QTitle" text set from server, you'll need to set "runat" attribute to "server" in your input, but, if you're using standard (X)HTML elements, you won't have such property "Text".
I suggest you to use a server control like TextBox which has the whole "Text" property:
<asp:TextBox ID="QTitle" runat="server" CssClass="Violet" />
Some server code-behind:
QTitle.Text = "Hello world";
Another suggestion is you won't be setting any property after PreRender ASP.NET Page life-cycle event.
Is the mark-up at the top of your question the resulting html or the source code for the form you are working with? If this is in-fact your asp.net form, try replacing the input tag with the following...
<asp:TextBox id="QTitle" runat="server" />
If the form is properly linked to the C# codebehind file you are using, QTitle.Text should now be accessible.

Resources