4 Answers, 1 is accepted
You can try out the following sample code to achieve the required scenario. In the example below, I use a FormTemplate with a RadComboBox, a hidden TextBox(Percentage) and another TextBox(Amount). On selecting a particular value from the combobox, the hidden textbox is made visible and on text change of the percentage textbox the amount textbox is populated:
aspx:
<EditFormSettings EditFormType="Template" > |
<FormTemplate> |
<telerik:RadComboBox ID="RadComboBox1" AutoPostBack="true" DataSourceID="SqlDataSource1" DataTextField="Text" runat="server" OnSelectedIndexChanged="RadComboBox1_SelectedIndexChanged"> |
</telerik:RadComboBox> |
<asp:TextBox ID="percentagetxt" AutoPostBack="true" runat="server" Visible="false" OnTextChanged="percentagetxt_TextChanged"></asp:TextBox> |
<asp:TextBox ID="amttxt" runat="server"></asp:TextBox> |
</FormTemplate> |
</EditFormSettings> |
c#:
protected void RadComboBox1_SelectedIndexChanged(object o, RadComboBoxSelectedIndexChangedEventArgs e) |
{ |
RadComboBox combo = (RadComboBox)o; |
GridEditFormItem item = (GridEditFormItem)combo.NamingContainer; |
if (combo.SelectedItem.Text == "5") |
{ |
TextBox txt = (TextBox)item.FindControl("percentagetxt"); |
txt.Visible = true; |
} |
} |
protected void percentagetxt_TextChanged(object sender, EventArgs e) |
{ |
TextBox percentagetxt = (TextBox)sender; |
GridEditFormItem item = (GridEditFormItem)percentagetxt.NamingContainer; |
TextBox txt = (TextBox)item.FindControl("amttxt"); |
txt.Text = percentagetxt.Text;// perform calculation here |
} |
Thanks
Princy.
I do not have a editform template but I am using the below code and I am getting null exception ?
TextBox t = (TextBox)gridInvLines.FindControl("txtpercentage");
how would I access this textbox ? below is my aspx code:
<telerik:RadGrid ID="gridInvLines" AllowPaging="False" Skin="Office2007"
runat="server" AutoGenerateColumns="False" DataSourceID="odsInvLines"
GridLines="None" OnItemCommand="gridInvLines_ItemCommand" OnItemDataBound="gridInvLines_ItemDataBound" ShowFooter="True">
<ClientSettings >
<ClientEvents OnKeyPress="disableEnterKey" OnPopUpShowing="PopUpShowing" />
</ClientSettings>
<MasterTableView DataKeyNames="LINE_NUMBER" DataSourceID="odsInvLines" EditMode="PopUp" InsertItemDisplay="Top" AllowAutomaticInserts="true" AllowAutomaticUpdates="true" AllowAutomaticDeletes="true" CommandItemDisplay="Top" CommandItemSettings-AddNewRecordText="Add New Line">
<Columns>
<telerik:GridTemplateColumn HeaderText="Activity Code" UniqueName="tcActivityCode">
<HeaderStyle width="60px" />
<ItemStyle HorizontalAlign="center" width="60px" />
<ItemTemplate>
<asp:Label ID="lblActivityCode" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "ACTIVITY_CODE_DESC") %>'>
</asp:Label>
</ItemTemplate>
<EditItemTemplate>
<telerik:RadComboBox ID="rcbActivityCodes" runat="server" Height="200px" Width="180px"
AllowCustomText="False" ShowToggleImage="True" ShowMoreResultsBox="false"
EnableLoadOnDemand="True" DropDownWidth="650px" DataTextField="DESCRIPTION" DataSource='<%# LoadActivityCodes() %>'
MarkFirstMatch="True" SelectedValue='<%# Bind("REV_ACTIVITY_CODE_ID")%>' DataValueField="REV_ACTIVITY_CODE_ID"
Text='<%# DataBinder.Eval(Container.DataItem, "ACTIVITY_CODE_DESC") %>' AppendDataBoundItems="true" OnClientItemsRequesting="" AutoPostBack="true" Skin="Office2007"
OnSelectedIndexChanged="rcbActivityCodes_SelectedIndexChanged">
<HeaderTemplate>
<table style="width: 650px" cellspacing="0" cellpadding="0">
<tr>
<td style="width: 200px;">
Description</td>
<td style="width: 200px;">
Account</td>
<td style="width: 250px;">
Category</td>
</tr>
</table>
</HeaderTemplate>
<ItemTemplate>
<table style="width: 650px" cellspacing="0" cellpadding="0">
<tr>
<td style="width: 200px;">
<%# DataBinder.Eval(Container.DataItem,"DESCRIPTION")%>
</td>
<td style="width: 200px;">
<%# DataBinder.Eval(Container.DataItem, "ACCOUNT")%>
- <%# DataBinder.Eval(Container.DataItem, "ACCOUNT_DESCRIPTION")%>
</td>
<td style="width: 250px;">
<%# DataBinder.Eval(Container.DataItem,"CATEGORY")%>
-
<%# DataBinder.Eval(Container.DataItem,"CATEGORY_DESCRIPTION")%>
</td>
</tr>
</table>
</ItemTemplate>
</telerik:RadComboBox>
</EditItemTemplate>
</telerik:GridTemplateColumn>
<telerik:GridBoundColumn DataField="TOTAL_AMOUNT" HeaderText="Total Amount" DataFormatString="{0:c}" ReadOnly="true" ForceExtractValue="None">
<HeaderStyle Width="50px" />
<ItemStyle HorizontalAlign="Right" Width="50px" />
</telerik:GridBoundColumn>
<telerik:GridTemplateColumn Visible="false" UniqueName="percentage">
<EditItemTemplate >
<asp:TextBox ID="txtpercentage" runat="server" Visible="false" />
</EditItemTemplate>
</telerik:GridTemplateColumn>
</Columns>
<EditFormSettings EditColumn-UpdateText="Save" EditColumn-InsertText="Save" CaptionFormatString="Invoice Line Information" ColumnNumber="2">
<FormTableItemStyle Wrap="False" Width="100%"></FormTableItemStyle>
<FormCaptionStyle CssClass="EditFormHeader" Width="100%"></FormCaptionStyle>
<FormMainTableStyle GridLines="Horizontal" CellSpacing="0" CellPadding="3" BackColor="White"
Width="100%" />
<FormTableStyle CellSpacing="0" CellPadding="2" CssClass="module" Height="110px"
BackColor="White" />
<FormTableAlternatingItemStyle Wrap="False"></FormTableAlternatingItemStyle>
<PopUpSettings Modal="true" Width="600" />
</EditFormSettings>
</MasterTableView>
<ValidationSettings CommandsToValidate="PerformInsert,Update" />
</telerik:RadGrid>
protected
void rcbActivityCodes_SelectedIndexChanged(object o, RadComboBoxSelectedIndexChangedEventArgs e)
{
RadComboBox combo = (RadComboBox)o;
PlaceHolder ph = combo.Parent as PlaceHolder;
GridEditableItem editItem = (GridEditableItem)ph.NamingContainer;
RadNumericTextBox t = (RadNumericTextBox)editItem.FindControl("rntPercentage");
Label l = (Label)editItem.FindControl("lblPercentage");
if (combo.SelectedItem.Attributes["ACCOM_SALE_FLAG"].ToString().ToUpper() == ConfigurationManager.AppSettings["c_TRUE"].ToString())
{
t.Visible =
true;
l.Visible =
true;
}
else
{
t.Visible =
false;
l.Visible =
false;
}
}
protected void rntPercentage_TextChanged(object sender, EventArgs e)
{
RadNumericTextBox percent = (RadNumericTextBox)sender;
PlaceHolder ph = percent.Parent as PlaceHolder;
GridEditableItem editItem = (GridEditableItem)ph.NamingContainer;
RadNumericTextBox amt = (RadNumericTextBox)editItem.FindControl("rntUnitPrice");
amt.Value = percent.Value;
// perform calculation here
}
I cannot get the parent and NamingContainer in javascript ? how would I do them ?
PlaceHolder ph = combo.Parent as PlaceHolder;
GridEditableItem editItem = (GridEditableItem)ph.NamingContainer; ?
function ShowPercentage(sender, eventArgs)
{
var sender = sender;
var item = eventArgs.get_item();
var att = item.get_attributes().getAttribute("ACCOM_SALE_FLAG");
}