How to bind dropdownlist in radgrid - telerik-grid

I am new to use telerik controls. I want to bind data in dropdownlist that is in telerik RadGrid control. I have already been applied but it gives an error
Object reference not set to an instance of an object.
Here is my code given below :
Source code
<telerik:RadGrid runat="server" ID="RadGrid1" AutoGenerateColumns="false" AllowPaging="true"
OnNeedDataSource="RadGrid1_NeedDataSource" OnUpdateCommand="RadGrid1_UpdateCommand"
OnItemCreated="RadGrid1_ItemCreated" OnDeleteCommand="RadGrid1_DeleteCommand"
OnInsertCommand="RadGrid1_InsertCommand"
onitemdatabound="RadGrid1_ItemDataBound" >
<MasterTableView DataKeyNames="id" CommandItemDisplay="Top" InsertItemPageIndexAction="ShowItemOnCurrentPage">
<Columns>
<telerik:GridEditCommandColumn ButtonType="ImageButton" />
<telerik:GridBoundColumn DataField="id" HeaderText="ID" ReadOnly="true"
ForceExtractValue="Always" ConvertEmptyStringToNull="true" />
<telerik:GridTemplateColumn>
<ItemTemplate>
<asp:DropDownList ID="ddldept" DataTextField="name" DataValueField="id" runat="server"></asp:DropDownList>
</ItemTemplate>
</telerik:GridTemplateColumn>
<telerik:GridBoundColumn DataField="code" HeaderText="Branch Code" />
<telerik:GridBoundColumn DataField="name" HeaderText="Branch Name" />
<telerik:GridBoundColumn DataField="shortname" HeaderText="Branch Shorth Name" />
<telerik:GridBoundColumn DataField="hod" HeaderText="Head of Department"/>
<telerik:GridBoundColumn DataField="location" HeaderText="Location Address" />
<telerik:GridButtonColumn ConfirmText="Are you sure want to delete this Branch?" ConfirmDialogType="RadWindow"
ConfirmTitle="Delete" ButtonType="ImageButton" CommandName="Delete" />
</Columns>
<EditFormSettings>
<EditColumn ButtonType="ImageButton" />
</EditFormSettings>
</MasterTableView>
<PagerStyle Mode="NextPrevAndNumeric" />
<ClientSettings>
<ClientEvents OnRowDblClick="rowDblClick" />
</ClientSettings>
</telerik:RadGrid>
Main Code
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
{
DataTable dt=obj.display_branch();
GridEditableItem item = e.Item as GridEditableItem;
DropDownList list = item.FindControl("ddldept") as DropDownList;
list.DataSource = dt;
list.DataTextField = "name";
list.DataValueField = "id";
list.DataBind();
}

Try on RadGrid1_ItemCreated. That is how I achieved it.

Related

Acumatica - Grid in PXTabItem on PXSmartPanel Not Appearing on Screen

I have a PXSmartPanel on the Sales Orders form (SO301000) in Acumatica ERP (v21.109.0018). In the PXSmartPanel I have a PXTab with two PXTabItem's. Each tab item has a PXGrid in it.
Whenever the smart panel opens, the grid in the first tab item shows with the correct data. But when I select the other tab item, the grid doesn't show at all (no data, no column names, no toolbar actions). I'm not sure if there's an attribute that I'm missing, but any help would be appreciated.
Here is my ASPX code for the PXSmartPanel. The grid with the ID "GridKitNonStkComponents" is the one that isn't showing:
<px:PXSmartPanel runat="server" ID="KitComponentsPanel" DesignView="Content" AllowResize="true"
AcceptButtonID="KitComponentSaveButton" CancelButtonID="KitComponentCancelButton" LoadOnDemand="true"
CaptionVisible="true" Caption="Kit Component Items" Key="KitComponentsPanel"
AutoRepaint="true" style="position:static;" Height="400px" Width="560px">
<px:PXTab ID="kitCompTab" runat="server" Width="100%" Height="85%">
<Items>
<px:PXTabItem Text="Stock Components">
<Template>
<px:PXGrid runat="server" ID="GridKitStkComponents" Height="100%" Width="100%" SyncPosition="true">
<Levels>
<px:PXGridLevel DataMember="KitStkComponents">
<Columns>
<px:PXGridColumn DataField="CompInventoryID" Width="70" CommitChanges="True" />
<px:PXGridColumn DataField="CompDescription" Width="280" />
<px:PXGridColumn DataField="ComponentQty" />
</Columns>
</px:PXGridLevel>
</Levels>
<ActionBar Position="Top">
<Actions>
<AddNew MenuVisible="True" />
<Save MenuVisible="False" Enabled="False" />
<Search MenuVisible="False" Enabled="False" />
<NoteShow Enabled="False" MenuVisible="False" />
<Refresh MenuVisible="True" />
<Delete MenuVisible="True" />
<AdjustColumns MenuVisible="True" />
<ExportExcel MenuVisible="True" />
</Actions>
<CustomItems>
<px:PXToolBarButton>
<AutoCallBack Command="ResetStkCompsToDefault" Target="ds">
<Behavior CommitChanges="true" />
</AutoCallBack>
</px:PXToolBarButton>
</CustomItems>
</ActionBar>
<AutoSize Enabled="true" />
</px:PXGrid>
</Template>
</px:PXTabItem>
<px:PXTabItem Text="Non-Stock Components" LoadOnDemand="true">
<Template>
<px:PXGrid runat="server" ID="GridKitNonStkComponents" Height="100%" Width="100%" SyncPosition="true">
<Levels>
<px:PXGridLevel DataMember="KitNonStkComponents">
<Columns>
<px:PXGridColumn DataField="CompInventoryID" Width="70" CommitChanges="True" />
<px:PXGridColumn DataField="CompDescription" Width="280" />
<px:PXGridColumn DataField="ComponentQty" />
</Columns>
</px:PXGridLevel>
</Levels>
<ActionBar Position="Top">
<Actions>
<AddNew MenuVisible="True" />
<Save MenuVisible="False" Enabled="False" />
<Search MenuVisible="False" Enabled="False" />
<NoteShow Enabled="False" MenuVisible="False" />
<Refresh MenuVisible="True" />
<Delete MenuVisible="True" />
<AdjustColumns MenuVisible="True" />
<ExportExcel MenuVisible="True" />
</Actions>
<CustomItems>
<px:PXToolBarButton>
<AutoCallBack Command="ResetNonStkCompsToDefault" Target="ds">
<Behavior CommitChanges="true" />
</AutoCallBack>
</px:PXToolBarButton>
</CustomItems>
</ActionBar>
<AutoSize Enabled="true" />
</px:PXGrid>
</Template>
</px:PXTabItem>
</Items>
</px:PXTab>
<px:PXPanel ID="KitComponentButtonPanel" runat="server" SkinID="Buttons">
<px:PXButton ID="KitComponentSaveButton" runat="server" DialogResult="OK" Text="Save" />
<px:PXButton ID="KitComponentCancelButton" runat="server" DialogResult="Cancel" Text="Cancel" />
</px:PXPanel>
</px:PXSmartPanel>
Here is the code for my graph extension (at the moment, the EditKitComponents action just opens the smart panel):
public class SOOrderEntry_Extension : PXGraphExtension<SOOrderEntry>
{
public static bool IsActive() => true;
#region Selects / Views
public SelectFrom<SOLineKitComponent>.
Where<SOLineKitComponent.soOrderType.IsEqual<SOLine.orderType.FromCurrent>.
And<SOLineKitComponent.soOrderNbr.IsEqual<SOLine.orderNbr.FromCurrent>>.
And<SOLineKitComponent.soLineNbr.IsEqual<SOLine.lineNbr.FromCurrent>>.
And<SOLineKitComponent.kitInventoryID.IsEqual<SOLine.inventoryID.FromCurrent>>.
And<SOLineKitComponent.stkItem.IsEqual<True>>>.View KitStkComponents;
public SelectFrom<SOLineKitComponent>.
Where<SOLineKitComponent.soOrderType.IsEqual<SOLine.orderType.FromCurrent>.
And<SOLineKitComponent.soOrderNbr.IsEqual<SOLine.orderNbr.FromCurrent>>.
And<SOLineKitComponent.soLineNbr.IsEqual<SOLine.lineNbr.FromCurrent>>.
And<SOLineKitComponent.kitInventoryID.IsEqual<SOLine.inventoryID.FromCurrent>>.
And<SOLineKitComponent.stkItem.IsEqual<False>>>.View KitNonStkComponents;
public SelectFrom<SOOrder>.View KitComponentsPanel;
#endregion
#region Actions
public PXAction<SOOrder> EditKitComponents;
[PXButton]
[PXUIField(DisplayName = "Edit Kit Components")]
public virtual void editKitComponents()
{
if(KitComponentsPanel.AskExt() == WebDialogResult.OK)
{
}
}
#endregion
}
Here is what the smart panel looks like when the different tab items are selected:
Tab Item with Grid Showing
Tab Item with Grid Not Showing
You need to set the "LoadOnDemand" to false for the whole PXSmartPanel to have the second tab working.
<px:PXSmartPanel runat="server" ID="KitComponentsPanel"
...
LoadOnDemand="False"
...
>
I would also consider setting LoadOnDemand to false for the second tab.
<px:PXTabItem Text="Non-Stock Components" LoadOnDemand="false">

Callback when Ext.NET Combobox local query returns no data

Using Ext.NET combobox.
<ext:ComboBox runat="server"
ID="ComboBoxCategorizedList"
QueryMode="Local"
ValueField="Id"
EmptyText="Type to begin search..."
TypeAhead="false"
DisplayField="Name"
Width="500"
NoteAlign="Down" EnableKeyEvents="true"
Note="Press 'Search' icon or Press ENTER for more results"
RemoveClearTrigger="true">
<%--Note="Type '*' for a full list"--%>
<HtmlBin>
<ext:XScript runat="server">
<script type="text/javascript">
$(window).on("__refresh__", function () {
#{ StoreComboBoxCategorizedList }.reload();
});
</script>
</ext:XScript>
</HtmlBin>
<Store>
<ext:Store runat="server" ID="StoreComboBoxCategorizedList" OnReadData="ComboBoxCategorizedList_ReadData">
<Proxy>
<ext:PageProxy />
</Proxy>
<Model>
<ext:Model Id="ModelCategorizedComboBox" runat="server" IDProperty="Id">
<Fields>
<ext:ModelField Name="Id" />
<ext:ModelField Name="Name" />
<ext:ModelField Name="Type" />
<ext:ModelField Name="RefId" />
<ext:ModelField Name="Description" />
</Fields>
</ext:Model>
</Model>
<Listeners>
<Update Handler="#{ComboBoxCategorizedList}.expand();" />
<EndUpdate Handler="categorizedList();" />
</Listeners>
<Parameters>
<ext:StoreParameter Mode="Raw" Name="filter" Value="#{ComboBoxCategorizedList}.getValue()" />
</Parameters>
</ext:Store>
</Store>
<Triggers>
<ext:FieldTrigger Icon="Clear"/>
<ext:FieldTrigger Icon="Search"></ext:FieldTrigger>
</Triggers>
<Listeners>
<SpecialKey Fn="enterKeyPressHandler" />
<Expand Handler="categorizedList();" Delay="100" />
<BeforeSelect Fn="onBeforeSelect" />
<KeyPress Handler="#{ComboBoxCategorizedList}.getTrigger(1).onClick();" Buffer="1000" />
<Change Handler="filterComboxBoxFunction(#{StoreComboBoxCategorizedList}, #{ComboBoxCategorizedList}.getValue()); #{ComboBoxCategorizedList}.expand(); categorizedList();" Delay="100" />
</Listeners>
Not asking for debugging help, but I want to know if an Ext.NET or Extjs dev has a generic solution: Very simply ... I want to initiate a remote search only when the local search returns no records. So I am looking for the best way to wire this up to the combobox. I've looked at using the Expand event and BeforeQuery event but this seems to come up short.
I'm looking for best practices so i can add a "OnLocalQuery" event to my comboboxes; and then take action if the local query returns 0 matches.
I use this function and it works fine .. and without QueryMode="Local":
<ext:ComboBox ID="cmb_name" runat="server" FieldLabel="ComboBox" EmptyText="-Select-" HideTrigger="true" TriggerAction="All" SelectOnFocus="true" DisplayField="Name" ValueField="Id" Editable="true" TabIndex="11">
<Store>
<ext:Store ID="str_ComboBox" runat="server" PageSize="10">
<Model>
<ext:Model ID="mdl_ComboBox" runat="server">
<Fields>
<ext:ModelField Name="Id" />
<ext:ModelField Name="Name" />
<ext:ModelField Name="Type" />
<ext:ModelField Name="RefId" />
<ext:ModelField Name="Description" />
</Fields>
</ext:Model>
</Model>
</ext:Store>
</Store>
<Listeners>
<Change Fn="fn_filter" />
</Listeners>
</ext:ComboBox>
<script type="text/javascript">
var fn_filter = function (_this, newValue, oldValue, eOpts) {
var n = 0;
if (_this.lastQuery == undefined || _this.lastQuery == null) {
_this.lastQuery = "";
}
_this.getStore().clearFilter(true);
_this.getStore().load();
_this.store.filter(function (item) {
if (item.get('Name').includes(_this.getRawValue())) {
n = n + 1;
return true;
}
else {
return false;
}
});
_this.expand();
if (n == 0) {
//returns no records
//enter code here Callback
}
}
</script>

Use of CSAttributes in new pages

We have a new page where we are looking to use the CS Attributes similarly to how they are used in the Item Class and Non Stock item pages
Item Class: Attribute definition.
Non Stock item page: Attribute implementation.
NOTE: I simplified the page to narrow down any potentially needed attributes in the ASPX.
Based on this, my Attribute definition page has the following elements:
Graph:
#region Datamembers
public PXSelect<MDEquipmentType> EquipmentType;
[PXViewName("Attributes")]
public CSAttributeGroupList<MDEquipmentType, MDEquipment> Mapping;
#endregion
ASPX:
<px:PXTabItem Text="Attributes">
<Template>
<px:PXGrid ID="grid" runat="server" DataSourceID="ds" Height="150px" Style="z-index: 100;
border: 0px;" Width="100%" ActionsPosition="Top" SkinID="Details" MatrixMode="True">
<Levels>
<px:PXGridLevel DataMember="Mapping">
<RowTemplate>
<px:PXSelector CommitChanges="True" ID="edAttributeID" runat="server" DataField="AttributeID" AllowEdit="True" FilterByAllFields="True" />
</RowTemplate>
<Columns>
<px:PXGridColumn DataField="IsActive" AllowNull="False" TextAlign="Center" Type="CheckBox" />
<px:PXGridColumn DataField="AttributeID" Width="81px" AutoCallBack="true" LinkCommand="CRAttribute_ViewDetails" />
<px:PXGridColumn AllowNull="False" DataField="Description" Width="351px" />
<px:PXGridColumn DataField="SortOrder" TextAlign="Right" Width="81px" SortDirection="Ascending" />
<px:PXGridColumn AllowNull="False" DataField="Required" TextAlign="Center" Type="CheckBox" />
<px:PXGridColumn AllowNull="True" DataField="CSAttribute__IsInternal" TextAlign="Center" Type="CheckBox" />
<px:PXGridColumn AllowNull="False" DataField="ControlType" Type="DropDownList" Width="81px" />
<px:PXGridColumn AllowNull="True" DataField="DefaultValue" Width="100px" RenderEditorText="False" />
</Columns>
</px:PXGridLevel>
</Levels>
<AutoSize Enabled="True" MinHeight="150" />
</px:PXGrid>
</Template>
</px:PXTabItem>
Result:
So far so good, all records are persisted in the DB correctly in the table CSAttributeGroup
Now, the problem comes when I try to apply the attributes in the data entry page.
This is the page:
When the Equipment Type is set, the attribute grid does not populate.
Graph definition:
public class MDEquipmentEntry : PXGraph<MDEquipmentEntry, MDEquipment>
{
#region Datamembers
public PXSelect<MDEquipment> Equipment;
public CRAttributeList<MDEquipment> Answers;
ASPX:
<px:PXTabItem Text="Attributes">
<Template>
<px:PXGrid ID="PXGridAnswers" runat="server" Caption="Attributes" DataSourceID="ds" SkinID="Inquire" Width="100%" Height="200px" MatrixMode="True">
<Levels>
<px:PXGridLevel DataMember="Answers">
<Columns>
<px:PXGridColumn DataField="AttributeID" />
<px:PXGridColumn DataField="isRequired" TextAlign="Center" Type="CheckBox" Width="80px"/>
<px:PXGridColumn DataField="Value" Width="300px" AllowShowHide="False" AllowSort="False" />
</Columns>
<Layout FormViewHeight="" />
</px:PXGridLevel>
</Levels>
<AutoSize Enabled="True" MinHeight="200" />
<ActionBar>
<Actions>
<Search Enabled="False" />
</Actions>
</ActionBar>
<Mode AllowAddNew="False" AllowColMoving="False" AllowDelete="False" />
</px:PXGrid>
</Template>
</px:PXTabItem>
In the Nonstock item page the attribute is loaded immediately after inserting the Item Class. So I made sure that the commitChanges attribute was added to my page. Also looked for a FieldUpdated event that could be triggering the insertion but that does not appear to be needed.
What could be missing from my code?
The implementation of CRAttributeList depends on a class ID field being defined somewhere in your class. Upon initialization, CRAttributeList will look for a field in your MDEquipment DAC decorated with the CRAttributesField attribute.
For the InventoryItem DAC, here's how it is defined:
[CRAttributesField(typeof(InventoryItem.itemClassID))]
public virtual string[] Attributes { get; set; }
If system is unable to determine the current class ID, your attributes grid will not be populated with anything.

Ext Net TimeField in an editable grid

I have a grid panel which display two TimeSpans in two columns and all is well when I load the page but when I go server side the validation on my editors always fail. I don't understand why the store can display the TimeSpans but cannot return it after...
Here my code :
<ext:GridPanel ID="WeekParams" runat="server" >
<Store>
<ext:Store runat="server">
<Reader>
<ext:JsonReader IDProperty="GUID">
<Fields>
<ext:RecordField Name="Day" Type="String" />
<ext:RecordField Name="UATNumber" Type="int" />
<ext:RecordField Name="From" Type="Date" />
<ext:RecordField Name="To" Type="Date" />
</Fields>
</ext:JsonReader>
</Reader>
</ext:Store>
</Store>
<ColumnModel>
<Columns>
<ext:Column ColumnID="Day" DataIndex="Day" />
<ext:NumberColumn ColumnID="UATNumber" DataIndex="UATNumber" Format="0" />
<ext:DateColumn ColumnID="From" DataIndex="From" Format="dd/MM/yyyy" >
<Renderer Format="Date" FormatArgs="'HH:mm'" />
<Editor>
<ext:TimeField runat="server" />
</Editor>
</ext:DateColumn>
<ext:DateColumn ColumnID="To" DataIndex="To" Format="dd/MM/yyyy" >
<Renderer Format="Date" FormatArgs="'HH:mm'" />
<Editor>
<ext:TimeField runat="server" />
</Editor>
</ext:DateColumn>
</Columns>
</ColumnModel>
<Plugins>
<ext:EditableGrid runat="server" />
</Plugins>
</ext:GridPanel>
And here the result when I'm going to the server side :

Update row in Gridview?

I have updated a row in Gridview but it is not working.
Here is my code :
protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
GridViewRow row = (GridViewRow)GridView1.Rows[e.RowIndex];
//Label lbldeleteid = (Label)row.FindControl("Label1");
string bname= GridView1.DataKeys[e.RowIndex].Values["manufacturer"].ToString();
TextBox tbmanu = (TextBox)GridView1.Rows[e.RowIndex].Cells[0].Controls[1];
var myString = tbmanu.ToString();
SqlCommand cmd = new SqlCommand("manu_upd",con);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add("#manufacturer", SqlDbType.NVarChar,100);
cmd.Parameters["#manufacturer"].Value = myString;
con.Open();
cmd.ExecuteNonQuery();
con.Close();
GridView1.EditIndex = -1;
BindData();
I got the following error :
Unable to cast object of type 'System.Web.UI.LiteralControl' to type
'System.Web.UI.WebControls.TextBox'.
here is my Grid view :
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
CellPadding="4" DataKeyNames="manufacturer" ForeColor="#333333"
GridLines="None" Width="400px" BorderStyle="Double"
CellSpacing="3" Font-Bold="True" Font-Size="Small" ShowFooter="True"
ShowHeaderWhenEmpty="True" onrowdeleting="GridView1_RowDeleting"
onrowediting="GridView1_RowEditing"
onrowupdating="GridView1_RowUpdating"
onrowcancelingedit="GridView1_RowCancelingEdit"
AutoGenerateEditButton="True">
<AlternatingRowStyle BackColor="White"/>
<Columns>
<asp:TemplateField HeaderText="Number" ItemStyle-
HorizontalAlign="Center">
<ItemTemplate>
<asp:Label ID="lbnaumber" runat="server" Text='<%#
Container.DataItemIndex + 1 %>'></asp:Label>
</ItemTemplate>
<ItemStyle HorizontalAlign="Center"></ItemStyle>
</asp:TemplateField>
<asp:TemplateField HeaderText="Manufacturer"
SortExpression="manufacturer">
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%#
Bind("manufacturer") %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="tbmanu" runat="server" Text='<%#
Bind("manufacturer") %>'></asp:TextBox>
</EditItemTemplate>
<ItemStyle HorizontalAlign="Center" />
</asp:TemplateField>
<%--<asp:CommandField ShowEditButton="True" />--%>
<asp:CommandField ShowDeleteButton="True" />
</Columns>
<EditRowStyle BackColor="#2461BF"/><FooterStyle BackColor="#507CD1"
Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White"/>
<PagerStyle BackColor="#2461BF" ForeColor="White"
HorizontalAlign="Center" />
<RowStyle BackColor="#EFF3FB" /><SelectedRowStyle BackColor="#D1DDF1"
Font-Bold="True" ForeColor="#333333" />
<SortedAscendingCellStyle BackColor="#F5F7FB"/>
<SortedAscendingHeaderStyle BackColor="#6D95E1" />
<SortedDescendingCellStyle BackColor="#E9EBEF" />
<SortedDescendingHeaderStyle BackColor="#4870BE" />
</asp:GridView>
When I change the index of my text box 1 to 3 it shows me below error :
Specified argument was out of the range of valid values.
Parameter name: index
When i change its index 3 to 2 it gives me below error :
Unable to cast object of type 'System.Web.UI.WebControls.DataControlLinkButton' to type 'System.Web.UI.WebControls.TextBox'.
I have one required field validator in my form but when I enable that validation update in grid view is not working.
protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
GridViewRow row = GridView1.Rows[e.RowIndex];
TextBox tbmanu1 = (TextBox)row.FindControl("tbmanu");
//or try
//TextBox tbmanu1= (TextBox)row.Cells[0].FindControl("tbmanu");
string myString = Convert.Tostring(tbmanu1.text);
cmd.Parameters["#manufacturer"].Value = myString;
}
Try wrapping your gridview in a asp:UpdatePanel and set the update mode to conditional.
Good Luck

Resources