I am trying to get access to the controls on the template´s grid but says Null reference Exception dont know what errors I am doing in.
I just use a template to add new record and to edit a record. I am ussing in my code this
RadGridExpensesLines_InsertCommand(
protected
void RadGridExpensesLines_InsertCommand(object sender, Telerik.Web.UI.GridCommandEventArgs e)
{
if (e.CommandName == RadGrid.PerformInsertCommandName)
{
GridEditFormInsertItem editedItem = e.Item as GridEditFormInsertItem;
PurchaseInvoiceLine purchaseline = new PurchaseInvoiceLine();
purchaseline.ArticleName = (editedItem.FindControl(
"RadTextBoxArticleName") as TextBox).Text;
}
In my aspx:
<telerik:RadGrid ID="RadGridLines" runat="server" AutoGenerateColumns="false" GridLines="None" OnNeedDataSource="RadGridExpensesLines_NeedDataSource" OnInsertCommand="RadGridExpensesLines_InsertCommand">
<
asp:Button ID="ButtonInsert" Text="Insert" runat="server" CommandName="PerformInsert" Visible="true"></asp:Button>
I tried also with
protected
void RadGridExpensesLines_ItemCommand(object sender, GridCommandEventArgs e)
but any success!!!!
Please someone can tell me why can not access to my controls on the template?
Please really need a help!
9 Answers, 1 is accepted
I dont know how to access to my template´s controls. I saw in the commanditem is too early to get the controls, but as I said before on my post, one I load the page I set on true the addrecord so it opens with the adding new record and also on my template I need to bind radcombox.
Please if someone can help me. I just really confuse and i have search on the telerik demos but dont appears this case and also in the forum. Please let me know how could I do this:
On my grid I have a template form, with just a few fields, not all, I need to bind some combos on the edit form, and when i insert and update I stored these values on a data structure which I bind my grid (a list) and after insert update or delete I save all to the data base. Please someone can give me a hint!
Best regards,
Thanks!
I suppose you want to access RadTextBox in Insert mode. here is the sample code.
C#:
protected void RadGridExpensesLines_InsertCommand(object sender, Telerik.Web.UI.GridCommandEventArgs e){ GridEditFormInsertItem editedItem = e.Item as GridEditFormInsertItem; RadTextBox txt= (RadTextBox)editedItem.FindControl("RadTextBoxArticleName");}Thanks,
Shinu
I really dont know how to do it...it is strange!
Please if you can help me, I will appreciate it!!!
Thanks!
Are you used EditForms as EditMode ? (if yes then please provide your code.)
like :
<MasterTableView EditMode="EditForms">Thanks,
Jayesh Goyani
I finally resolve it, it was because of the typecast, I made a typecast to asp controls instead rad controls.
line.Article = (container.FindControl(
"RadTextBoxArticle") as RadTextBox).Text;
But I have a problem now, as I said I use EditForm, but when I am trying to edit a row, the items I want to show them on its corresponding controls. For example: if I select row one and it has Article, Amount, IVA, I want the values will be show in the controls, but when I am trying to edit, are blanck.
This is my Template form:
<EditFormSettings EditFormType="Template">
<FormTemplate>
You can bind the text as shown below.
aspx:
<telerik:RadTextBox ID="RadTextBox1" runat="server" Text='<%#Bind("ID")%>'></telerik:RadTextBox>Thanks,
Shinu
I tried with this but in the case of the radcombobox says databinding methods such as Eval, Xpas, and bind can only be used in the context of a databound cotrol: This is how I bind my combo: I populate my combobox in OnItemDataBond. Hope you can help me! Thanks!!!
<
telerik:RadComboBox ID="RadComboBoxTax" runat="server" DataValueField="Id" DataTextField="Description" SelectedValue='<%# Bind("TaxId") %>' CausesValidation="false" MarkFirstMatch="true" AllowCustomText="false" DropDownAutoWidth="Enabled"></telerik:RadComboBox>
You can bind the selected value in edit mode as shown below.
C#:
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e){ if(e.Item is GridEditableItem && e.Item.IsInEditMode) { GridEditableItem item = (GridEditableItem)e.Item; RadComboBox combo = (RadComboBox)item.FindControl("RadComboBoxTax"); combo.SelectedValue = (string)DataBinder.Eval(e.Item.DataItem, "TaxId").ToString(); }}Thanks,
Shinu