Hi,
I have the following grid:
<TELERIK:RADGRID ID="RadGridProductCharacteristics" runat="server" AutoGenerateColumns="false" AllowAutomaticUpdates="true" OnItemUpdated="RadGridProductCharacteristics_ItemUpdated" OnItemDataBound="RadGridProductCharacteristics_ItemDataBound" OnItemCommand="RadGridProductCharacteristics_ItemCommand" OnPreRender="RadGridProductCharacteristics_PreRender">
<CLIENTSETTINGS AllowGroupExpandCollapse="true" />
<MASTERTABLEVIEW DataKeyNames="CharacteristicID" GroupLoadMode="Client" CommandItemDisplay="Top" EditMode="Batch">
<BATCHEDITINGSETTINGS EditType="Cell" />
<GROUPBYEXPRESSIONS>
<TELERIK:GRIDGROUPBYEXPRESSION>
<GROUPBYFIELDS>
<TELERIK:GRIDGROUPBYFIELD FieldName="ParentCharacteristicName" />
</GROUPBYFIELDS>
<SELECTFIELDS>
<TELERIK:GRIDGROUPBYFIELD FieldName="ParentCharacteristicName" HeaderText="Parent Characteristic" />
</SELECTFIELDS>
</TELERIK:GRIDGROUPBYEXPRESSION>
</GROUPBYEXPRESSIONS>
<COLUMNS>
<TELERIK:GRIDBOUNDCOLUMN HeaderText="Characteristic" DataField="CharacteristicName" ReadOnly="true" />
<TELERIK:GRIDBOUNDCOLUMN UniqueName="CharacteristicValue" HeaderText="Value" DataField="CharacteristicValue" />
<TELERIK:GRIDTEMPLATECOLUMN HeaderText="Color" UniqueName="CharacteristicColor" DataField="CharacteristicColor">
<ITEMTEMPLATE>
<%# Eval("CharacteristicColor") %>
</ITEMTEMPLATE>
<EDITITEMTEMPLATE>
<TELERIK:RADDROPDOWNLIST runat="server" ID="RadDropDownListColor" />
</EDITITEMTEMPLATE>
</TELERIK:GRIDTEMPLATECOLUMN>
<TELERIK:GRIDBUTTONCOLUMN UniqueName="ImageButtonDelete" HeaderText="Action" ButtonType="ImageButton" ImageUrl="~/Resources/Images/icon_delete.png" CommandName="Delete" />
</COLUMNS>
</MASTERTABLEVIEW>
</TELERIK:RADGRID>
I would like to fill the RadDropDownListColor so it is filled when the user clicks the cell to edit the value.
I checked this article: Column Editors and from there I derived the following code:
protected void RadGridProductCharacteristics_PreRender(object sender, EventArgs e)
{
GridTableView masterTable = (sender as RadGrid).MasterTableView;
RadDropDownList radDropDownListColor = masterTable.GetBatchColumnEditor("CharacteristicColor") as RadDropDownList;
radDropDownListColor.DataSource = DBCom.GetHTMLColors();
radDropDownListColor.DataTextField = "HTMLColorName";
radDropDownListColor.DataValueField = "HTMLColorCode";
radDropDownListColor.DataBind();
radDropDownListColor.Items.Insert(0, new DropDownListItem("", "0"));
}
But still the variable radDropDownListColor is null.
What am I doing wrong?
Iam using telerik grid of asp.net
I want to disable column "telerik:GridNumericColumn " in below code snippet on changing "telerik:GridDropDownColumn" I am not aware of how to handle selection change event of GridDropDownColumn on server side and make one column disabled.
Please help in this regard.
Regards, Kiran
Below is the radgrid declaration
<telerik:RadGrid ID="rg" runat="server"
AllowSorting="False"
AutoGenerateColumns="False" Width="730px" Height="263px"
OnUpdateCommand="rg_Update"
OnInsertCommand="rg_Insert"
OnDeleteCommand="rg_Delete"
OnItemCreated="rg_ItemCreated"
OnItemCommand="rg_ItemCommand"
OnSelectedIndexChanged="rg_SelectedIndexChanged"
OnNeedDataSource="rg_NeedDataSource"
OnDataBound="rg_DataBound"
GridLines="None"
CellSpacing="0"
MasterTableView-Caption="Routing Rules">
<ClientSettings AllowKeyboardNavigation="true" EnablePostBackOnRowClick="true">
<Scrolling AllowScroll="True" UseStaticHeaders="True" />
<Selecting AllowRowSelect="True" />
</ClientSettings>
<MasterTableView CommandItemDisplay="Top" DataKeyNames="Id,IndexId">
<CommandItemSettings AddNewRecordText="Add New Routing Rule" />
<Columns>
<telerik:GridButtonColumn UniqueName="editButton" ButtonType="ImageButton" CommandName="Edit" FilterControlAltText="Filter editButton column"
HeaderText="Edit" HeaderStyle-Width="34px" ItemStyle-HorizontalAlign="Left" Resizable="false"
ImageUrl="~\Images\pencil.png">
</telerik:GridButtonColumn>
<telerik:GridButtonColumn UniqueName="deleteButton" ButtonType="ImageButton" CommandName="Delete" FilterControlAltText="Filter deleteButton column"
HeaderText="Delete" HeaderStyle-Width="47px" ItemStyle-HorizontalAlign="Left" Resizable="false"
ImageUrl="~\Images\delete.png"
ConfirmDialogType="RadWindow" ConfirmText="Are you sure you want to delete this record?">
</telerik:GridButtonColumn>
<telerik:GridBoundColumn Visible="false" DataField="Id" UniqueName="RoutingRuleRuleId" ReadOnly="True" />
<telerik:GridNumericColumn DataField="Priority" UniqueName="RoutingRulePriority" HeaderText="Priority" DataType="System.Int32" MaxLength="3" />
<telerik:GridDropDownColumn
HeaderText="Rule Type" DataField="RoutingRuleDefinitionId" SortExpression="uRuleType" UniqueName="uRuleType"
ColumnEditorID="myRuleTypeDropDownEditor"
ListTextField="Name" ListValueField="Id" EnableEmptyListItem="True"
EmptyListItemValue="0" Visible="False">
</telerik:GridDropDownColumn>
</MasterTableView>
</telerik:RadGrid>
Hi, I want to have a column in radgrid batch edit and that column can contain either a textbox or dropdown based on a condition of the binding dataset. How can I implement this?
Thanks
So in my RadGrid I have a template column that contains RadDropDownList in the EditItemTemplate. When this is modified in a row I would like to loop through the RadGrid and modify the other RadDropDownList in the other rows. I know how to loop through the grid but having trouble accessing the dropdown since the other rows are not in edit mode. Using the changeCellValue(cellToUpdate, value) of the BatchEditingManager but not having any luck with updating the dropdown.
<BatchEditingSettings EditType="Cell" />
<telerik:GridTemplateColumn HeaderText="IsBudget" UniqueName="IsBudget" SortExpression="IsBudget">
<ItemTemplate>
<asp:Label ID="lblIsBudget" runat="server" Text='<%# Eval("IsBudget") %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<telerik:RadDropDownList ID="ddIsBudget" RenderMode="Lightweight" runat="server" DataValueField="IsBudget" >
<Items>
<telerik:DropDownListItem Text="False" Value="False" />
<telerik:DropDownListItem Text="True" Value="True" />
</Items>
</telerik:RadDropDownList>
</EditItemTemplate>
</telerik:GridTemplateColumn>
Hello!
I am trying to configure my updatecommand for a RadGrid dropdownlist edit entry. I have attached the code for the dropdownlist and my current update command below
DropDownList
if (e.Item is GridEditableItem && e.Item.IsInEditMode && !(e.Item is GridEditFormInsertItem))
{
SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["DBConnectionString"].ConnectionString);
SqlDataAdapter da = new SqlDataAdapter("SELECT * FROM [ExampleDB].[dbo].[Status]", connection);
DataSet ds = new DataSet();
da.Fill(ds);
GridEditableItem edit = (GridEditableItem)e.Item;
TextBox txt = (TextBox)edit["Status"].Controls[0];
txt.Visible = false;
DropDownList droplist = new DropDownList();
droplist.DataSource = ds;
droplist.DataTextField = "Name";
droplist.DataValueField = "ID";
droplist.DataBind();
edit["OrderStatus"].Controls.Add(droplist);
}
Update Command
protected void RadGrid1_UpdateCommand(object sender, GridCommandEventArgs e)I have done extensive research on this issue and have yet to find a solution that works. I have a simple RadGrid, 2 columns are Template Columns. Each of those 2 columns have a RadDropDownList (DDL) with SQL Data Sources. I would like the selection of the first DDL to define the data list of the second DDL. Also, this needs to work in Insert and Edit modes.
I am stuck at two instances, at one point the first DDL - after making a selection it posts-back and loses the selected item. It resets to "- Select -" and does not bind the second DDL with any data.
Another is when I get an error that states I can't use Eval, Bind, etc., to a non-databound control.
Please take a look at my code and point me in the correct direction!
<telerik:RadGrid ID="rgvHDwithLoc" runat="server" AutoGenerateColumns="False" DataSourceID="sdsHDwithLoc" AllowAutomaticDeletes="True" AllowAutomaticInserts="True" AllowAutomaticUpdates="True" AutoGenerateDeleteColumn="false" AutoGenerateEditColumn="False">
<GroupingSettings CollapseAllTooltip="Collapse all groups" />
<MasterTableView AllowAutomaticDeletes="True" AllowAutomaticInserts="True" AllowAutomaticUpdates="True" CommandItemDisplay="Top" DataKeyNames="owedRequestID" DataSourceID="sdsHDwithLoc" EditMode="EditForms">
<CommandItemSettings ShowCancelChangesButton="false" ShowSaveChangesButton="false" />
<Columns>
<telerik:GridEditCommandColumn EditText="Edit" UpdateText="Update" CancelText="Cancel" HeaderText="Edit"></telerik:GridEditCommandColumn>
<telerik:GridButtonColumn ButtonType="ImageButton" CommandName="Delete" ConfirmText="Are you sure you want to delete this record?" ConfirmTitle="Delete Adjustment" FilterControlAltText="Filter delete column" HeaderText="Delete" UniqueName="delete">
</telerik:GridButtonColumn>
<telerik:GridBoundColumn DataField="owedRequestID" DataType="System.Int32" FilterControlAltText="Filter owedRequestID column" HeaderText="owedRequestID" ReadOnly="True" SortExpression="owedRequestID" UniqueName="owedRequestID" Display="false">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="wageAdjRequestID" DataType="System.Int32" FilterControlAltText="Filter wageAdjRequestID column" HeaderText="wageAdjRequestID" SortExpression="wageAdjRequestID" UniqueName="wageAdjRequestID" Display="false" ReadOnly="true">
</telerik:GridBoundColumn>
<telerik:GridTemplateColumn DataField="sapWageCode" FilterControlAltText="Filter sapWageCode column" HeaderText="Wage Code" SortExpression="sapWageCode" UniqueName="sapWageCode">
<EditItemTemplate>
<telerik:RadDropDownList ID="ddlsapWageCode" runat="server" SelectedValue='<%# Bind("sapWageCode") %>' DataTextField="sapWageCodeAndName" DataValueField="sapWageCode" DataSourceID="sdsWageCode" Width="400" DefaultMessage="- Select -" AutoPostBack="True" CausesValidation="false" EnableViewState="true" OnSelectedIndexChanged="ddlsapWageCode_SelectedIndexChanged"></telerik:RadDropDownList>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="sapWageCodeLabel" runat="server" Text='<%# Eval("sapWageCode") %>'></asp:Label>
</ItemTemplate>
</telerik:GridTemplateColumn>
<telerik:GridTemplateColumn DataField="sapAttnCode" FilterControlAltText="Filter sapAttnCode column" HeaderText="Attn Code" SortExpression="sapAttnCode" UniqueName="sapAttnCode">
<EditItemTemplate>
<telerik:RadDropDownList ID="ddlsapAttnCode" runat="server" DataTextField="sapAttnCodeAndName" DataValueField="sapAttnCode" Width="400" SelectedValue='<%# Eval("sapAttnCode")%>' DefaultMessage="- Select -"></telerik:RadDropDownList>
</EditItemTemplate>
<InsertItemTemplate>
<telerik:RadDropDownList ID="ddlsapAttnCode" runat="server" DataTextField="sapAttnCodeAndName" DataValueField="sapAttnCode" Width="400" DefaultMessage="- Select -"></telerik:RadDropDownList>
</InsertItemTemplate>
<ItemTemplate>
<asp:Label ID="sapAttnCodeLabel" runat="server" Text='<%# Eval("sapAttnCode") %>'></asp:Label>
</ItemTemplate>
</telerik:GridTemplateColumn>
<telerik:GridBoundColumn DataField="sapWorkCenter" FilterControlAltText="Filter sapWorkCenter column" HeaderText="Work Center" SortExpression="sapWorkCenter" UniqueName="sapWorkCenter">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="sapDept" FilterControlAltText="Filter sapDept column" HeaderText="Dept" SortExpression="sapDept" UniqueName="sapDept">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="Hours" DataType="System.Decimal" FilterControlAltText="Filter Hours column" HeaderText="Hours" SortExpression="Hours" UniqueName="Hours">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="RatePay" DataType="System.Decimal" FilterControlAltText="Filter RatePay column" HeaderText="RatePay" SortExpression="RatePay" UniqueName="RatePay">
</telerik:GridBoundColumn>
<telerik:GridDateTimeColumn DataField="Date" DataType="System.DateTime" FilterControlAltText="Filter Date column" HeaderText="Date" SortExpression="Date" UniqueName="Date" DataFormatString="{0:d}">
</telerik:GridDateTimeColumn>
<telerik:GridTemplateColumn DataField="sapJobCode" FilterControlAltText="Filter sapJobCode column" HeaderText="Job Code" SortExpression="sapJobCode" UniqueName="sapJobCode">
<EditItemTemplate>
<telerik:RadDropDownList ID="ddlsapJobCode" runat="server" DataSourceID="sdsJobCode" DataTextField="sapJobCodeAndName" DataValueField="sapJobCode" SelectedValue='<%# Bind("sapJobCode") %>' Width="400" DefaultMessage="- Select -"></telerik:RadDropDownList>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="sapJobCodeLabel" runat="server" Text='<%# Eval("sapJobCode") %>'></asp:Label>
</ItemTemplate>
</telerik:GridTemplateColumn>
</Columns>
<EditFormSettings>
<EditColumn FilterControlAltText="Filter EditCommandColumn1 column" UniqueName="EditCommandColumn1">
</EditColumn>
</EditFormSettings>
</MasterTableView>
</telerik:RadGrid>
<asp:SqlDataSource ID="sdsHDwithLoc" runat="server" ConnectionString="<%$ ConnectionStrings:XXXXXX_SAP %>"
DeleteCommand="DELETE FROM [tblSAP_HoursDollarsOwedRequest] WHERE [owedRequestID] = @owedRequestID"
SelectCommand="SELECT * FROM view_SAP_WageAdjRequest_hoursDollarsOwed WHERE (wageAdjRequestID = @wageAdjRequestID)"
UpdateCommand="UPDATE tblSAP_HoursDollarsOwedRequest SET sapWageCode = @sapWageCode, sapAttnCode = @sapAttnCode, sapWorkCenter = @sapWorkCenter, sapDept = @sapDept, Hours = @Hours, RatePay = @RatePay, sapJobCode = @sapJobCode, Date = @Date WHERE (owedRequestID = @owedRequestID)"
InsertCommand="INSERT INTO tblSAP_HoursDollarsOwedRequest (wageAdjRequestID, sapWageCode, sapAttnCode, sapWorkCenter, sapDept, Hours, RatePay, sapJobCode, [Date]) VALUES (@wageAdjRequestID, @sapWageCode, @sapAttnCode, @sapWorkCenter, @sapDept, @Hours, @RatePay, @sapJobCode, @Date)">
<SelectParameters>
<asp:ControlParameter ControlID="lblWageAdjID" PropertyName="Text" Name="wageAdjRequestID" Type="Int32" />
</SelectParameters>
<DeleteParameters>
<asp:Parameter Name="owedRequestID" Type="Int32" />
</DeleteParameters>
<UpdateParameters>
<asp:Parameter Name="sapWageCode" Type="String" />
<asp:Parameter Name="sapAttnCode" Type="String" />
<asp:Parameter Name="sapWorkCenter" Type="String" />
<asp:Parameter Name="sapDept" Type="String" />
<asp:Parameter Name="Hours" Type="Decimal" />
<asp:Parameter Name="RatePay" Type="Decimal" />
<asp:Parameter Name="sapJobCode" Type="String" />
<asp:Parameter Name="Date" Type="DateTime" />
<asp:Parameter Name="owedRequestID" Type="Int32" />
</UpdateParameters>
<InsertParameters>
<asp:ControlParameter ControlID="lblWageAdjID" PropertyName="text" Name="wageAdjRequestID" Type="Int32" />
<asp:Parameter Name="sapWageCode" Type="String" />
<asp:Parameter Name="sapAttnCode" Type="String" />
<asp:Parameter Name="sapWorkCenter" Type="String" />
<asp:Parameter Name="sapDept" Type="String" />
<asp:Parameter Name="Hours" Type="Decimal" />
<asp:Parameter Name="RatePay" Type="Decimal" />
<asp:Parameter Name="sapJobCode" Type="String" />
<asp:Parameter Name="Date" Type="DateTime" />
</InsertParameters>
</asp:SqlDataSource>
<asp:SqlDataSource ID="sdsWageCode" runat="server" ConnectionString="<%$ ConnectionStrings:XXXXXX_SAP %>"
SelectCommand="SELECT [sapWageCode], sapWageCode + ' - ' + sapWageCodeName AS sapWageCodeAndName FROM [tblSAP_WageCode] WHERE [sapWageCodeActive] = 1 ORDER BY [sapWageCodeName]"></asp:SqlDataSource>
<asp:SqlDataSource ID="sdsAttnCode" runat="server" ConnectionString="<%$ ConnectionStrings:XXXXXX_SAP %>"
SelectCommand="SELECT [sapAttnCode], sapAttnCode + ' - ' + sapAttnCodeName AS sapAttnCodeAndName FROM [tblSAP_AttnCode] WHERE [sapAttnCodeActive] = 1 AND sapWageCode = @sapWageCode">
<SelectParameters>
<asp:ControlParameter ControlID="ddlsapWageCode" PropertyName="SelectedValue" Name="sapWageCode" Type="String" />
</SelectParameters>
</asp:SqlDataSource>
And I have tried this in my VB code behind:
Protected Sub ddlsapWageCode_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs)
Dim wageCodeDDL As RadDropDownList = CType(sender, RadDropDownList)
Dim insertItem As GridEditFormInsertItem = CType(wageCodeDDL.NamingContainer, GridEditFormInsertItem)
Dim attnCodeDDL As RadDropDownList = CType(insertItem.FindControl("ddlsapAttnCode"), RadDropDownList)
Dim strWageCode = wageCodeDDL.SelectedValue.ToString
Dim strAttnCode As String = Nothing
Dim strAttnCodeAndName As String = Nothing
Dim myConn As New SqlConnection(ConfigurationManager.ConnectionStrings("XXXXXX_SAP").ConnectionString)
Dim strSelect As String = "SELECT [sapAttnCode], sapAttnCode + ' - ' + sapAttnCodeName AS sapAttnCodeAndName FROM [tblSAP_AttnCode] WHERE [sapAttnCodeActive] = 1 AND sapWageCode = @sapWageCode"
Dim myCmd As New SqlCommand(strSelect, myConn)
myConn.Open()
With myCmd.Parameters
.Add(New SqlParameter("@sapWageCode", strWageCode))
End With
Dim dr As SqlDataReader = myCmd.ExecuteReader
While dr.Read
strAttnCode = dr("sapAttnCode")
strAttnCodeAndName = dr("sapAttnCodeAndName")
End While
myConn.Close()
myCmd.Dispose()
myConn.Dispose()
dr.Close()
attnCodeDDL.DataValueField = strAttnCode
attnCodeDDL.DataTextField = strAttnCodeAndName
attnCodeDDL.DataBind()
End Sub