This is a migrated thread and some comments may be shown as answers.

[Solved] Plz help with RadGrid Template form!

9 Answers 123 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Joan
Top achievements
Rank 1
Joan asked on 11 Mar 2013, 04:08 PM
Hi again!
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

Sort by
0
Joan
Top achievements
Rank 1
answered on 11 Mar 2013, 04:22 PM
Could someone give me any suggestion plz...
0
Joan
Top achievements
Rank 1
answered on 11 Mar 2013, 09:43 PM
Telerik team, I have been looking for a solution for this issue but cant find the right answer.
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! 
0
Shinu
Top achievements
Rank 2
answered on 12 Mar 2013, 04:37 AM
Hi,

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
0
Joan
Top achievements
Rank 1
answered on 12 Mar 2013, 07:57 AM
I tried to do it that way but says the component is null, so I can not access to it...
I really dont know how to do it...it is strange!
Please if you can help me, I will appreciate it!!!
Thanks!
0
Jayesh Goyani
Top achievements
Rank 2
answered on 12 Mar 2013, 08:13 AM
Hello,

Are you used EditForms as EditMode ? (if yes then please provide your code.)

like :
<MasterTableView EditMode="EditForms">


Thanks,
Jayesh Goyani
0
Joan
Top achievements
Rank 1
answered on 12 Mar 2013, 05:00 PM
I am ussing EditForm.
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>


 

 

0
Shinu
Top achievements
Rank 2
answered on 13 Mar 2013, 04:17 AM
Hi,

You can bind the text as shown below.
aspx:
<telerik:RadTextBox ID="RadTextBox1" runat="server"  Text='<%#Bind("ID")%>'></telerik:RadTextBox>

Thanks,
Shinu
0
Joan
Top achievements
Rank 1
answered on 13 Mar 2013, 08:13 AM
Hi 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>


0
Shinu
Top achievements
Rank 2
answered on 14 Mar 2013, 04:27 AM
Hi,

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
Tags
Grid
Asked by
Joan
Top achievements
Rank 1
Answers by
Joan
Top achievements
Rank 1
Shinu
Top achievements
Rank 2
Jayesh Goyani
Top achievements
Rank 2
Share this question
or